dotnet/aspnetcore · error · RuntimeException
Connection is not active.
Error message
Connection is not active.
What it means
getConnectionStateUnsynchronized(allowNull) is the unsynchronized accessor used by call sites that already hold the state lock. When allowNull is not true (false or null) and the internal ConnectionState field is null - meaning the connection was never started or has been fully torn down - it throws.
Solutions
- Call start() before any invoke/send/stream and do not call them after stop().
- Subscribe to onClosed and treat the connection as unusable until start() is called again.
- Track connection lifecycle in your own code and short-circuit public-API calls when stopped.
Example fix
// before
hub.stop();
hub.send("M"); // ConnectionState is null
// after
hub.start().blockingAwait();
hub.send("M"); Defensive patterns
Strategy: validation
Validate before calling
// This is internal; users guard by checking the public state.
if (hub.getConnectionState() != HubConnectionState.CONNECTED) {
// connection not active; do not invoke
} Try / catch
try {
hub.invoke("M").await();
} catch (RuntimeException e) {
if (e.getMessage().equals("Connection is not active.")) {
// start() then retry
} else throw e;
} Prevention
- Never call public API on a stopped/never-started HubConnection.
- After stop(), build a new HubConnection rather than reusing.
- Track lifecycle explicitly with an enum mirrored from onClosed/onReconnected.
When it happens
Trigger: An internal code path requests the ConnectionState without allowing null after the connection has been stopped (state set to null) but before a new start(); or before the very first start().
Common situations: Calling invoke/send/stream immediately after stop(); a stale callback firing after teardown; incorrect library usage where the public API is called against a never-started HubConnection.
Related errors
- The HubConnection failed to transition from the
- The 'invoke' method cannot be called if the connection is…
- The 'send' method cannot be called if the connection is not…
- The 'stream' method cannot be called if the connection is…
- There are no callbacks registered for the method
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/8b753241eeb98d56.
Report an issue: GitHub.
Appendix: source
Thrown at src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java:1689
private ConnectionState state;
private HubConnectionState hubConnectionState = HubConnectionState.DISCONNECTED;
public ReconnectingConnectionState(Logger logger) {
this.logger = logger;
}
public void setConnectionState(ConnectionState state) {
this.lock.lock();
try {
this.state = state;
} finally {
this.lock.unlock();
}
}
public ConnectionState getConnectionStateUnsynchronized(Boolean allowNull) {
if (allowNull != true && this.state == null) {
throw new RuntimeException("Connection is not active.");
}
return this.state;
}
public ConnectionState getConnectionState() {
this.lock.lock();
try {
if (this.state == null) {
throw new RuntimeException("Connection is not active.");
}
return this.state;
} finally {
this.lock.unlock();
}
}
public HubConnectionState getHubConnectionState() {
return this.hubConnectionState;View on GitHub (pinned to 3600ca084e)