Repository navigation
read kernel socket table for connections - #1002
Merged
Merged
Conversation
Oglopf
added a commit
that referenced
this pull request
Oct 20, 2026
The hang Jeff saw was the old port_used trying nc first. On RHEL and Fedora nc is ncat, where -w only limits the connect, so checking the port the skip test held open (accepting nothing) waited forever. shuf picked that port first about half the time. Rebasing onto #1002, which reads /proc/net/tcp instead, removes it. The tests now mostly check the generated script, as Jeff suggested. Two still run the startup, to show the picked port reaches vncserver and is the one the job reports. Those run under a 30s timeout, with BASH_ENV unset (Lmod makes every bash source its init), and the fake vncserver waits for its Xvnc like the real one does, so pgrep can't miss it. Skipping a port in use is find_port's job and is already tested in template_test.rb, so that test is gone.
1 task done
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.
What does this PR do?
port_usedreturned on the first strategy that gave an answer.ncruns first and is installed nearly everywhere, and it checks a port by connecting to it rather than asking whether it's bound. That misses ports held by outgoing connections, and it can hang on a listener that never closes the connection. Sofind_portcould hand out a port that was already in use.This replaces the chain with checks that read the kernel's socket table:
port_used_procreads/proc/net/tcpand/proc/net/tcp6directly. It needs nothing installed, sees every user's sockets, and handles hosts withouttcp6.port_used_ssreads the same data through iproute2. It tests the output rather than the exit status, sincessexits 0 even when nothing matches.port_used_lsofis kept as a last resort, but it only sees the calling user's sockets.The connect-based strategies (
nc, bash/dev/tcp,python) are removed, and the "no strategy available" message inwait_until_port_usedis updated to match.Please see #926 for results as to why the above are proposed to be removed.
Related issue
Closes #926
Testing
New minitest in
test/batch_connect/template_test.rb. It renders the real helpers and runs them in bash against real sockets: a listening port, a port held by an outgoing connection, a free port,tcp6,ss, andfind_portin both directions.template.rb, the outgoing-connection tests fail, and the listening-port test times out onnc.Checklist
Anything else?
Which fallbacks to keep is still open. This removes the connect-based strategies, which was option 1 in the #926 thread. If we'd rather keep them behind the new checks (option 2), it's a small change to restore the three functions and add them back to the end of
port_strategies. Nothing else changes.ssandlsofwill rarely run./proc/net/tcpis readable on any Linux host, so they only matter where/proc/netis restricted.Not in this PR:
wait_until_port_usedstill usesport_used, which counts a socket on the port in any state. For that caller, "listening" (state0A) would be the more exact test. I haven't seen it cause a problem, so I've left it out of this change.Docs follow-up: the requirements page lists
nmap-ncatas a compute node requirement for interactive apps. After this change, OnDemand's own helpers no longer callnc, so that entry can be dropped or reworded. I'll open a PR in ood-documentation once the fallback question above is settled, since option 2 would keepncin use. The web node'slsofrequirement is unrelated.