Fix TestTunnelE2ECLI and properly close listener in tunnelTraffic#6024
Open
benjirewis wants to merge 2 commits into
Open
Fix TestTunnelE2ECLI and properly close listener in tunnelTraffic#6024benjirewis wants to merge 2 commits into
benjirewis wants to merge 2 commits into
Conversation
Member
|
allisonschiang
approved these changes
May 19, 2026
Member
allisonschiang
left a comment
There was a problem hiding this comment.
lgtm in terms of it passes on windows, didn't look into implementation!
|
Hey @benjirewis — this PR has been approved and CI has been green for 3+ business days. Ready to merge? Auto-comment from overwatch. Will not re-nudge for 7 days. |
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.
RSDK-13993
RSDK-13994
What
Fixes two bugs in the CLI tunnel implementation and its test:
tunnelTrafficcouldn't be stopped via context cancellation. The accept loop checksctx.Err()only at the top of each iteration, butnet.Listener.Accept()blocks indefinitely. Cancelling the context had no effect while the listener was waiting for a new connection. Fixed by spawning a goroutine that closes the listener when the context is done, which causes Accept() to return an error and lets the loop exit cleanly.TestTunnelE2ECLIwasn't actually testing the tunnel.sourcePortanddestPortwere both set to 23657. Since the destination listener was already bound to localhost:23657 before tunnelTraffic started, the CLI listener failed to bind the same port (silently, in a goroutine). The test then dialedlocalhost:23657and connected directly to the destination listener, bypassing the tunnel entirely and passing vacuously. Fixed by setting sourcePort to23659(matching the port shown in the test's own comment) and usingtestutils.WaitForAssertionto retry the dial until tunnelTraffic's listener is ready.Why
The code fix makes
tunnelTrafficbehave correctly when a user cancels a tunnel session — without it, the CLI listener would hang indefinitely after cancellation. In production, this wasn't a huge deal since the OS (at least in my testing) seems to reclaim the port after the CLI is ctrl-ced 🤷🏻 .The test fix ensures we actually have coverage of the CLI tunnel path rather than a test that silently passes without exercising anything.
Testing
TestTunnelE2ECLI now passes and exercises the full tunnel path: test-process <-> source-listener(localhost:23659) <-> machine(localhost:23658) <-> dest-listener(localhost:23657). I also manually verified that
viam machine part tunnelstill works as expected.