Repository navigation
network: Let sta_rssi/0 take only its reply, and time out - #2452
Merged
Merged
Conversation
bettio
approved these changes
Oct 28, 2026
sta_rssi/0 sent its request to network_port and then received anything:
`Other -> {error, Other}` took the first message in the caller's mailbox,
so a gen_server or any process with other traffic lost that message and
got `{error, Message}`, while the real reply stayed behind for the next
call. And with no `after`, the caller waited forever when no reply came,
for example when the port went away between whereis/1 and the send.
It now receives only `{Ref, _}` for its own request, and returns
`{error, timeout}` after 5 s. A timeout does not cancel the request, so a
late reply may still reach the caller; the doc says so.
test_network runs sta_rssi/0 against a fake network_port.
Fixes atomvm#2433
Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
gabrielmancini
force-pushed
the
sta-rssi-timeout
branch
from
October 28, 2026 18:08
27b55be to
44fb61e
Compare
Author
|
Rebased on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2433, following @petermm's review there.
network:sta_rssi/0sent{self(), Ref, rssi}tonetwork_portand then received anything:Other -> {error, Other}took the first message in the caller's mailbox. A gen_server, or any process with other traffic (timers, socket data,'$gen_call's), lost that message and got{error, Message}, while the real reply stayed queued for the next call.after, the caller waited forever when no reply came, for example when the port went away betweenwhereis/1and the send.It now receives only
{Ref, {error, _}}and{Ref, {rssi, _}}for its own request, and returns{error, timeout}after 5000 ms. As the review points out, a timeout does not cancel the request, so a late{Ref, Reply}may still reach the caller's mailbox; the edoc says so. The request protocol, the/0API and the success/error mapping are unchanged, and the drivers are untouched.Test.
tests/libs/eavmlib/test_network.erlregisters a fakenetwork_portand checks:network_downwith no port; an unrelated message already in the mailbox is left there; a reply with another reference is ignored (and left there); an error reply is passed through; no reply gives{error, timeout}.test_networkfails with{badmatch,{error,unrelated}}; with it, all oftest_eavmlib.avmpasses.The timeout case makes
test_eavmlibabout 5 s longer.These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later