mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4255] [Other] serve: refuse a port another program holds on 127.0.0.1, and say which program #4975
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4975
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4255
Author: @ByteJuggler
Created: 10/26/2026
Status: 🔄 Open
Base:
main← Head:pr/port-in-use📝 Commits (3)
6742f84fix(serve): refuse a port another program holds on 127.0.0.1, and say which program9ef1a51tests: test_strata_bench's port-owner test finds serve/ when run as a script (tools\test_strata_bench.py)f58068afix(serve): a taken port still exits with status 2, as ap.error did📊 Changes
4 files changed (+178 additions, -5 deletions)
View changed files
📝
serve/server.py(+73 -3)📝
serve/test_server.py(+54 -0)📝
tools/strata_bench.py(+27 -2)📝
tools/test_strata_bench.py(+24 -0)📄 Description
Problem and result
Replaces #2168, which was closed in the 0.2.0-beta tracker reset; its branch was rebased on current
main, so GitHub cannot reopen it.On Windows, Strata on
0.0.0.0:8080can start beside another program that holds127.0.0.1:8080(Steam'ssteamwebhelper.exedoes on some PCs). The server saysready, but every client on the PC (web app, chat.py, coding tools, BENCH) reaches the other program, and the bench waits "still loading" for 10 minutes. Windows allows a wildcard bind next to another process's specific bind unless the socket usesSO_EXCLUSIVEADDRUSE.SO_REUSEADDRis already off (#769).After this change the start fails before the model loads, and the message names the program:
The bench's port check now counts any listener on the port, not only one that answers
/healthwith JSON (Steam answers 404), and names it:(Both outputs are from the original PR, run with Steam holding the port; see "Not run".)
Related discussion
#2168, where @qiuzan2001 reviewed it. Both points are addressed here:
tools/test_strata_bench.pyrun as a script could not importserve(ModuleNotFoundError): the test now puts the repo root onsys.path.ap.error, and the start exited with status 1 instead of 2: it now prints the message and exits with 2, and a test starts the real server on a taken port and checks the status and that no usage line is printed.Focused fix.
Approach
Server.server_bind:SO_EXCLUSIVEADDRUSEon Windows only. The existing early test bind inmain()then fails before the model loads (WinError 10048). Linux and Mac are unchanged.netstat/sscommand), says when it is probably Strata itself, and offers a port that is free now. It is printed without argparse's usage line in front, with the same exit status 2.tools/strata_bench.py: the pre-check counts any listener on the port and names it.Validation
Passed:
main5e8a4cca, 0.2.7), Windows 11, Python 3.12:python -m unittest discover -s serve -p "test_*.py" -t .: 1220 tests OK (47 skipped).python tools/test_strata_bench.py(run as a script): 24 tests OK.main5e8a4cca'sserve/server.pyandtools/strata_bench.py:test_all_addresses_cannot_be_bound_beside_a_loopback_listener(a real-socket test:0.0.0.0:Pmust not bind beside a127.0.0.1:Plistener) fails, so the bug is still present on 0.2.7.test_a_taken_port_exits_2_without_the_usage_linefails there (ap.errorprints the usage line), the message test errors, and the two bench port-check tests error.Failed:
Not run:
steamwebhelper.exelistener before the tracker reset (the outputs above); on 0.2.7 only the real-socket test was run.Limits
Program names need psutil. Without it the message falls back to the
netstat/sscommand.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.