Repository navigation
Conversation
start released its lock as soon as it had written $! to the PID file. During the loop's exec chain (nohup, TUNNEL_SHELL, sh) /proc/PID/cmdline is still the start script's or empty, so a start in that window took the PID for a stale one and started a second loop over the PID file; stop then ended only the second, and the first ran on. The loop now records itself and removes the lock. The tests count only the loops of their own config, check after every test that stop ended the loop, and repeat start right after start.
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.
Problem
pytest tests/unit/test_device_tunnel.pyfailed on main (5 of 6) on this host. A test run had leaked a loop (device-tunnel.sh run) that nothing stopped, andloops(tmp_path)counted every loop of the script on the host, not only the test's own.The leak came from the script.
startreleased its lock right after writing$!to the PID file. During the loop's exec chain (nohup→TUNNEL_SHELL→sh),/proc/PID/cmdlineis still the start script's or empty. Astartin that window took the PID for a stale one, started a second loop and overwrote the PID file.stopthen ended only the second loop. Back-to-back starts reproduced this in 7 of 40 rounds. It breaks the ssh-tunnel requirement that running the script again while a tunnel runs does not start a second one.Change
machine/ssh_tunnel/device-tunnel.sh:startkeeps the lock. The loop writes its own PID to the PID file and then removes the lock, so astartin between exits 0. If the loop dies earlier, the existing stale-lock handling (one minute) clears the lock.tests/unit/test_device_tunnel.py:loops()counts only loops with the test's ownTUNNEL_CONF.stopended the loop.test_start_right_after_start_runs_one_looprepeats start + start 15 times. The race is timing-dependent; it failed one of three runs against the old script.Validation
pytest tests/unit/test_device_tunnel.py -q: 7 passed, three runs in a row.pre-commit run --files machine/ssh_tunnel/device-tunnel.sh tests/unit/test_device_tunnel.py: passed.Not changed:
stopdoes not take the lock, so astopright afterstartcould still miss a loop that is just starting. This does not affect the boot task and watchdog, which only runstart.