Pull requests / #2168

#2168 serve: refuse a port another program holds on 127.0.0.1, and say which program

open · @ByteJuggler · 0 コメント · GitHub で見る

BenchmarksSetup & installServer & APIWindowsLinux

本文

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`.

関連リンク

インストール・モデル・リリースへの站内リンク。