SignalR "Failed to complete negotiation with the server" in CI
A SignalR client first POSTs to /hub/negotiate to learn the available transports and a connection token. "Failed to complete negotiation with the server" means that HTTP request failed, so no transport is ever established.
What this error means
Starting the connection rejects with "Error: Failed to complete negotiation with the server: Error". Tests flake when the hub server has not started listening yet.
Error: Failed to complete negotiation with the server: Error
at HttpConnection._getNegotiationResponse (node_modules/@microsoft/signalr/dist/cjs/HttpConnection.js:...)
at async HttpConnection._startInternal (...)Common causes
The hub server is not accepting requests yet
The negotiate POST hit a closed or not-yet-ready port, so the handshake fails before any transport is chosen.
Wrong hub URL or a blocked negotiate endpoint
A wrong path, or a proxy that blocks POST /hub/negotiate, prevents the client from ever getting a connection token.
How to fix it
Wait for the hub before starting the connection
- Ensure the SignalR host is listening (or poll the URL) before
connection.start(). - Confirm the hub URL and any base path match the server route.
- Retry
start()once on a transient negotiation failure.
await waitForHttp('http://localhost:5000/hub/negotiate');
await connection.start();Use the correct hub URL
Point the builder at the exact hub route the server maps.
const connection = new signalR.HubConnectionBuilder()
.withUrl('http://localhost:5000/hub')
.build();How to prevent it
- Poll the hub URL before starting the connection in tests.
- Keep the client hub URL in sync with the server route mapping.
- Allow negotiate requests through any proxy in the test topology.