-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix network.erl race conditions #1487
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, thanks for spotting my error in sta_rssi/0! Of course I should not have stated a new network_port if it was not yet open.
src/platforms/esp32/test/main/test_erl_sources/test_wifi_example.erl
Outdated
Show resolved
Hide resolved
b51790d
to
03dab59
Compare
This should be good to go. Of note there was an additional crash as sta_rssi() is unsafe to call before connection is made, and calling it instantly after network:start would driver crash (port is up but network is not connected) - thus extra guard in the driver. I fully understand that some supervisor should be introduced, and some contract decided upon eg. if network port ever disappears unexpected, or doesn't shutdown, exit and restart should happen?. But this a bugfix PR against release-0.6. After this one we can look at making 0.7 beautiful;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All is good, let's add a line to the fixed section of our changelog.
Cleaner, DRY code - and avoid any potential races. Signed-off-by: Peter M <[email protected]>
Calling network:sta_rssi() would crash if network was not started. And just if network_port was started but not connected yet. Handle this and return error tuple, and added tests for both scenarios. Signed-off-by: Peter M <[email protected]>
network:stop through terminate was using nonblocking call to stop network_port- so rapid stop/start would give the second network:start an old whereis(network_port) that was still shutting down, and lead to errors. Now waits for port DOWN. Signed-off-by: Peter M <[email protected]>
03dab59
to
6920c66
Compare
As evidenced by failing simtest CI on release-0.6 etc.
startup should use continue/handle_continue and avoid races + cleaner DRY code.
network:stop was using nonblocking call to stop network_port- so rapid stop/start would give the last network:start an old whereis(network_port) that was still shutting down, and lead to errors.
somewhat unrelated: sta_rssi was using get_port(), and would crash on no network started - guarded it erlang side, added test.
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