Skip to content

network: Let sta_rssi/0 take only its reply, and time out - #2452

Merged
bettio merged 1 commit into
atomvm:release-0.7from
iobee-io:sta-rssi-timeout
Oct 29, 2026
Merged

bettio merged 1 commit into
atomvm:release-0.7from
iobee-io:sta-rssi-timeout

Conversation

@gabrielmancini

Copy link
Copy Markdown

Fixes #2433, following @petermm's review there.

network:sta_rssi/0 sent {self(), Ref, rssi} to network_port and 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.
  • 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, {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 /0 API and the success/error mapping are unchanged, and the drivers are untouched.

Test. tests/libs/eavmlib/test_network.erl registers a fake network_port and checks: network_down with 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}.

  • generic_unix, without the fix: test_network fails with {badmatch,{error,unrelated}}; with it, all of test_eavmlib.avm passes.

The timeout case makes test_eavmlib about 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

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

Copy link
Copy Markdown
Author

Rebased on release-0.7 after #2436 was merged: the conflict was the CHANGELOG only, the code is the approved one.

@bettio
bettio merged commit 8284498 into atomvm:release-0.7 Oct 29, 2026
189 of 190 checks passed
@gabrielmancini
gabrielmancini deleted the sta-rssi-timeout branch October 30, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants