https://github.com/tkellogg/fastmcp-deadlock-repro
reproduces a deadlock bug in fastmcp
https://github.com/tkellogg/fastmcp-deadlock-repro
Last synced: 10 months ago
JSON representation
reproduces a deadlock bug in fastmcp
- Host: GitHub
- URL: https://github.com/tkellogg/fastmcp-deadlock-repro
- Owner: tkellogg
- Created: 2025-05-11T20:49:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-11T21:09:15.000Z (about 1 year ago)
- Last Synced: 2025-05-11T22:19:46.451Z (about 1 year ago)
- Language: Python
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deadlock Bug
This is reproducible in `streamable-http` and `sse` but not `stdio`. That makes me think it's a core
concurrency issue in `mcp`.
# Running
In all these examples, change the numeric argument on the client. What I've found
* 10 — works easily, fast
* 100 — works
* 200 — works in `streamable-http`, deadlock in `sse`
* 250 - deadlock in `streamable-http`
* 500 — deadlock
* 1000 — big deadlock
For both `streamable-http` and `sse`, the following error occurs frequently, followed by the script hanging:
```
Error in post_writer: All connection attempts failed
```
If it fails and I kill the client but not the server and re-run with a much lower number
(e.g. 250 and then 10), the second small run works fine.
conclusion: maybe the deadlock is in the client and the server is uneffected?
The `--tool-concurrency` flag changes the concurrency to not include connecting, one single connection
serves all threads and only a tool call is made. In my experiments, this doesn't trigger a deadlock issue.
## Running streamable-http
server:
```bash
uv run --script server.py streamable-http
```
client:
```bash
uv run --script client.py 0.0.0.0 8000 streamable-http 1000
```
## Running sse
server:
```bash
uv run --script server.py streamable-http
```
client:
```bash
uv run --script client.py 0.0.0.0 8000 sse 1000
```
## Running stdio
```bash
# lots of excess noise on stderr
uv run --script client.py 0.0.0.0 8000 stdio 10 2>/dev/null
```