Skip to content
Latchkey

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.

SignalR
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

  1. Ensure the SignalR host is listening (or poll the URL) before connection.start().
  2. Confirm the hub URL and any base path match the server route.
  3. Retry start() once on a transient negotiation failure.
test.mjs
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.

test.mjs
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.

Frequently asked questions

What causes ""Failed to complete negotiation with the server""?
The negotiate POST hit a closed or not-yet-ready port, so the handshake fails before any transport is chosen.
How do I fix "Failed to complete negotiation with the server"?
Wait for the hub before starting the connection

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card