commit | aba67f9a2a71cbcc7af1a1881b046a0a7bd7e0ca | [log] [tgz] |
---|---|---|
author | Octavian Purdila <tavip@google.com> | Wed Oct 18 18:05:21 2023 +0000 |
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | Wed Oct 18 18:05:21 2023 +0000 |
tree | 3d6b747b029ab3f96a09ee0c8a0a4a84342e320a | |
parent | 2f1d686f9f82655444bda5a9721db2ff661506c0 [diff] |
pw_emu: mock_emu: start listening before making the port available There is a race condition in mock_emu because we are making the port available (writing it to a file for clients to read) before marking the socket as listening. If the client gets to run after the port is written to the file but before the TCP thread has a chance to run we would get this error: ====================================================================== ERROR: test_channel_stream (__main__.TestEmulator) ---------------------------------------------------------------------- Traceback (most recent call last): File "../../pw_emu/py/tests/frontend_test.py", line 116, in test_channel_stream with self._emu.get_channel_stream('gdb') as _: File "/b/s/w/ir/x/w/co/pw_emu/py/pw_emu/frontend.py", line 256, in get_channel_stream return self._c().get_channel_stream(name, timeout) File "/b/s/w/ir/x/w/co/pw_emu/py/pw_emu/core.py", line 533, in get_channel_stream sock.connect((host, port)) ConnectionRefusedError: [Errno 111] Connection refused The fix is to mark the socket for listening before writing the port to the file. Bug: 306155313 Test: stress --cpu 512 and run frontend_test.py 100 times without failures Change-Id: I04d63c6271c8d3334bab3dd4713231475fd0e74d Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/176856 Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com> Pigweed-Auto-Submit: Octavian Purdila <tavip@google.com>
Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.
For more information please see our website: https://pigweed.dev/.