Title: `asyncio_websockets` uses a fixed port (8001) and fails with `EADDRINUSE` when two instances run concurrently · Issue #516 · python/pyperformance · GitHub
Open Graph Title: `asyncio_websockets` uses a fixed port (8001) and fails with `EADDRINUSE` when two instances run concurrently · Issue #516 · python/pyperformance
X Title: `asyncio_websockets` uses a fixed port (8001) and fails with `EADDRINUSE` when two instances run concurrently · Issue #516 · python/pyperformance
Description: asyncio_websockets uses a fixed port (8001) and fails with EADDRINUSE when two instances run concurrently Summary bm_asyncio_websockets/run_benchmark.py binds a hard-coded port 8001 for both the server and the client: async with websocke...
Open Graph Description: asyncio_websockets uses a fixed port (8001) and fails with EADDRINUSE when two instances run concurrently Summary bm_asyncio_websockets/run_benchmark.py binds a hard-coded port 8001 for both the se...
X Description: asyncio_websockets uses a fixed port (8001) and fails with EADDRINUSE when two instances run concurrently Summary bm_asyncio_websockets/run_benchmark.py binds a hard-coded port 8001 for both the se...
Opengraph URL: https://github.com/python/pyperformance/issues/516
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`asyncio_websockets` uses a fixed port (8001) and fails with `EADDRINUSE` when two instances run concurrently","articleBody":"# `asyncio_websockets` uses a fixed port (8001) and fails with `EADDRINUSE` when two instances run concurrently\n\n## Summary\n\n`bm_asyncio_websockets/run_benchmark.py` binds a hard-coded port `8001` for both\nthe server and the client:\n\n```python\nasync with websockets.server.serve(handler, \"\", 8001):\n async with websockets.client.connect(\"ws://localhost:8001\") as ws:\n```\n\nThe default suite runs this benchmark only once, so the fixed port does not\nconflict in a normal sequential run. However, it makes the benchmark impossible\nto run concurrently with itself, and it also fails if an unrelated process is\nalready using port 8001.\n\nI hit this while running every pyperformance sub-item in parallel, one process\nper benchmark. Only one instance of `asyncio_websockets` is in the suite today,\nso the parallel run passed, but a second instance (CI sharding, a custom runner,\nor running the benchmark twice at the same time) fails immediately. This is the\nsame class of problem as #514 (`asyncio_tcp` / `asyncio_tcp_ssl` on port 8882),\nreported separately because this benchmark needs its own fix and testing.\n\n## How to reproduce the issue\n\nUsing the public `pyperformance` interface:\n\n```bash\n# Make sure the shared venv already exists (run the benchmark once).\npython -m pyperformance run -b asyncio_websockets -f -o /tmp/warmup.json\n\n# Now run two instances concurrently.\npython -m pyperformance run -b asyncio_websockets -f -o /tmp/ws1.json &\npython -m pyperformance run -b asyncio_websockets -f -o /tmp/ws2.json &\nwait\n```\n\nThe same thing happens if the benchmark script is invoked directly twice:\n\n```bash\nBENCH=$(python -c 'import os, pyperformance; print(os.path.join(\n os.path.dirname(pyperformance.__file__),\n \"data-files\", \"benchmarks\", \"bm_asyncio_websockets\", \"run_benchmark.py\"))')\n\npython \"$BENCH\" -f --output /tmp/ws1.json &\npython \"$BENCH\" -f --output /tmp/ws2.json &\nwait\n```\n\n## What you expected to happen\n\nBoth instances should complete successfully:\n\n- instance 1: `Mean +- std dev: ...`\n- instance 2: `Mean +- std dev: ...`\n\n## What actually happens\n\nOne of the two processes dies at server startup:\n\n```\nTraceback (most recent call last):\n ...\n File \".../bm_asyncio_websockets/run_benchmark.py\", line 38, in main\n async with websockets.server.serve(handler, \"\", 8001):\n ...\nOSError: [Errno 98] error while attempting to bind on address ('::', 8001, 0, 0):\n[errno 98] address already in use\n```\n\nDepending on which address family wins the race, the failing address can be\nreported as `('0.0.0.0', 8001)` or `('::', 8001, 0, 0)`. With `pyperformance run`\nthe failure is reported as:\n\n```\nERROR: Benchmark asyncio_websockets failed: Benchmark died\n```\n\nRunning `asyncio_websockets` on its own succeeds, which confirms the failure is\ncaused by the fixed port rather than by the websocket code path.\n\n## Environment\n\n- pyperformance `1.14.0` (main at `8a0713c`)\n- Python `3.16.0a2+dev` (64-bit), but the fixed port is not version-specific\n- `websockets==11.0.3` (the version pinned by the benchmark)\n- Linux 5.15, x86_64\n\n## Possible fix\n\nBind port `0` and read the actual port back from the listening socket:\n\n```diff\n- async with websockets.server.serve(handler, \"\", 8001):\n- async with websockets.client.connect(\"ws://localhost:8001\") as ws:\n+ async with websockets.server.serve(handler, \"127.0.0.1\", 0) as server:\n+ port = server.sockets[0].getsockname()[1]\n+ async with websockets.client.connect(f\"ws://127.0.0.1:{port}\") as ws:\n await asyncio.gather(*[send(ws) for _ in range(100)])\n```\n","author":{"url":"https://github.com/sendaoYan","@type":"Person","name":"sendaoYan"},"datePublished":"2026-11-19T03:04:54Z","url":"https://github.com/python/pyperformance/issues/516"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9048f530-45ad-89a7-91dc-873a65469ba7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B92A:1148D3:3500A93:43A61B7:6B01E935 |
| html-safe-nonce | a4269850d8e4f34739fc43532f97405d9bec37bad74b9805d85c91b918a553f4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTJBOjExNDhEMzozNTAwQTkzOjQzQTYxQjc6NkIwMUU5MzUiLCJ2aXNpdG9yX2lkIjoiNDU1NzEzMDU2ODIzOTgwMjY3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dcadb020aafe9a9b9a65abb58566f808d339cf79894054822e5381824c4762a9 |
| hovercard-subject-tag | issue:6481450013 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/pyperformance/516/issue_layout |
| twitter:image | https://opengraph.githubassets.com/20a107fd3057c17bd9aa782b6bb08f64fc3b6101d2d14f3a0227d84eed3d82e0/python/pyperformance/issues/516 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/20a107fd3057c17bd9aa782b6bb08f64fc3b6101d2d14f3a0227d84eed3d82e0/python/pyperformance/issues/516 |
| og:image:alt | asyncio_websockets uses a fixed port (8001) and fails with EADDRINUSE when two instances run concurrently Summary bm_asyncio_websockets/run_benchmark.py binds a hard-coded port 8001 for both the se... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sendaoYan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/pyperformance git https://github.com/python/pyperformance.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 65949828 |
| octolytics-dimension-repository_nwo | python/pyperformance |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 65949828 |
| octolytics-dimension-repository_network_root_nwo | python/pyperformance |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width