[PR #2168] [CLOSED] serve: refuse a port another program holds on 127.0.0.1, and say which program #3898

Closed
opened 2026-11-07 15:31:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2168
Author: @ByteJuggler
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: pr/port-in-use


📝 Commits (2)

  • 958d98f fix(serve): refuse a port another program holds on 127.0.0.1, and say which program
  • 93df3c4 tests: test_strata_bench's port-owner test finds serve/ when run as a script (tools\test_strata_bench.py)

📊 Changes

4 files changed (+161 additions, -5 deletions)

View changed files

📝 serve/server.py (+72 -3)
📝 serve/test_server.py (+38 -0)
📝 tools/strata_bench.py (+27 -2)
📝 tools/test_strata_bench.py (+24 -0)

📄 Description

On Windows, Strata on 0.0.0.0:8080 could start beside another program holding 127.0.0.1:8080 (Steam's steamwebhelper.exe on some PCs). The server said ready, but every client on the PC (web app, chat.py, coding tools, BENCH) reached the other program. The bench then waited "still loading" for 10 minutes. Without SO_EXCLUSIVEADDRUSE, Windows allows a wildcard bind next to another process's specific bind; SO_REUSEADDR was already off (#769).

Changes

  • Server.server_bind: SO_EXCLUSIVEADDRUSE on Windows. The existing early test bind in main() now fails before the model loads (checked against a live Steam listener: WinError 10048).
  • The "port in use" message names the program and PID, says when it is probably Strata itself, offers a port that is free now, and gives the commands for this start (--port) and for good (SETUP.bat --port / ./setup.sh --setup --port). It is printed without argparse's usage line in front.
  • strata_bench.py: the pre-check counts any listener on the port, not only one that answers /health with JSON (Steam answers 404), and names it.

Before

server.py: error: port 8080 is already in use - ...      (only when the bind failed; in the Steam case it did not)

After (--host 0.0.0.0 --port 8080, Steam running)

[strata] cannot start: port 8080 is already in use by steamwebhelper.exe (PID 36952) on 127.0.0.1.
It listens only on this PC's own address, but programs on this PC (the web app, chat.py, your coding tools) use http://127.0.0.1:8080 and would reach it instead of Strata.
Close that program, or give Strata another port (8081 is free now):
  - this start only: add --port 8081
  - from now on: run setup again with --port 8081 (Windows: SETUP.bat --port 8081; Linux: ./setup.sh --setup --port 8081)
  then point your clients at http://127.0.0.1:8081/v1

Bench:

Port 8080 on this PC already answers, but not as Strata: it is steamwebhelper.exe (PID 36952) on 127.0.0.1.
Close that program, or run the benchmark on another port: BENCH.bat --port 8081 (or python tools/strata_bench.py --port 8081).

Tests

  • A real-socket test that 0.0.0.0:P cannot be bound beside a 127.0.0.1:P listener (fails before this change on Windows), message tests, and bench port-check tests.
  • serve.test_server passes (310). tools/ has 3 failures in test_setup_engine_hash.WhatARefusalDoesToTheCaller, which fail the same way on main.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2168 **Author:** [@ByteJuggler](https://github.com/ByteJuggler) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/port-in-use` --- ### 📝 Commits (2) - [`958d98f`](https://github.com/Niko1221/Strata/commit/958d98f3b392f93cfce692451b74728d4421022f) fix(serve): refuse a port another program holds on 127.0.0.1, and say which program - [`93df3c4`](https://github.com/Niko1221/Strata/commit/93df3c445b3ec5e0fc7566e7a1a9f21a473cee0d) tests: test_strata_bench's port-owner test finds serve/ when run as a script (tools\test_strata_bench.py) ### 📊 Changes **4 files changed** (+161 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+72 -3) 📝 `serve/test_server.py` (+38 -0) 📝 `tools/strata_bench.py` (+27 -2) 📝 `tools/test_strata_bench.py` (+24 -0) </details> ### 📄 Description On Windows, Strata on `0.0.0.0:8080` could start beside another program holding `127.0.0.1:8080` (Steam's `steamwebhelper.exe` on some PCs). The server said `ready`, but every client on the PC (web app, chat.py, coding tools, BENCH) reached the other program. The bench then waited "still loading" for 10 minutes. Without `SO_EXCLUSIVEADDRUSE`, Windows allows a wildcard bind next to another process's specific bind; `SO_REUSEADDR` was already off (#769). **Changes** - `Server.server_bind`: `SO_EXCLUSIVEADDRUSE` on Windows. The existing early test bind in `main()` now fails before the model loads (checked against a live Steam listener: `WinError 10048`). - The "port in use" message names the program and PID, says when it is probably Strata itself, offers a port that is free now, and gives the commands for this start (`--port`) and for good (`SETUP.bat --port` / `./setup.sh --setup --port`). It is printed without argparse's usage line in front. - `strata_bench.py`: the pre-check counts any listener on the port, not only one that answers `/health` with JSON (Steam answers 404), and names it. **Before** ``` server.py: error: port 8080 is already in use - ... (only when the bind failed; in the Steam case it did not) ``` **After** (`--host 0.0.0.0 --port 8080`, Steam running) ``` [strata] cannot start: port 8080 is already in use by steamwebhelper.exe (PID 36952) on 127.0.0.1. It listens only on this PC's own address, but programs on this PC (the web app, chat.py, your coding tools) use http://127.0.0.1:8080 and would reach it instead of Strata. Close that program, or give Strata another port (8081 is free now): - this start only: add --port 8081 - from now on: run setup again with --port 8081 (Windows: SETUP.bat --port 8081; Linux: ./setup.sh --setup --port 8081) then point your clients at http://127.0.0.1:8081/v1 ``` Bench: ``` Port 8080 on this PC already answers, but not as Strata: it is steamwebhelper.exe (PID 36952) on 127.0.0.1. Close that program, or run the benchmark on another port: BENCH.bat --port 8081 (or python tools/strata_bench.py --port 8081). ``` **Tests** - A real-socket test that `0.0.0.0:P` cannot be bound beside a `127.0.0.1:P` listener (fails before this change on Windows), message tests, and bench port-check tests. - `serve.test_server` passes (310). `tools/` has 3 failures in `test_setup_engine_hash.WhatARefusalDoesToTheCaller`, which fail the same way on `main`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:31:31 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3898
No description provided.