{"record":{"id":"8b753241eeb98d56","repo":"dotnet/aspnetcore","slug":"connection-is-not-active","errorCode":null,"errorMessage":"Connection is not active.","messagePattern":"Connection is not active\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java","lineNumber":1689,"sourceCode":"        private ConnectionState state;\n        private HubConnectionState hubConnectionState = HubConnectionState.DISCONNECTED;\n\n        public ReconnectingConnectionState(Logger logger) {\n            this.logger = logger;\n        }\n\n        public void setConnectionState(ConnectionState state) {\n            this.lock.lock();\n            try {\n                this.state = state;\n            } finally {\n                this.lock.unlock();\n            }\n        }\n\n        public ConnectionState getConnectionStateUnsynchronized(Boolean allowNull) {\n            if (allowNull != true && this.state == null) {\n                throw new RuntimeException(\"Connection is not active.\");\n            }\n            return this.state;\n        }\n\n        public ConnectionState getConnectionState() {\n            this.lock.lock();\n            try {\n                if (this.state == null) {\n                    throw new RuntimeException(\"Connection is not active.\");\n                }\n                return this.state;\n            } finally {\n                this.lock.unlock();\n            }\n        }\n\n        public HubConnectionState getHubConnectionState() {\n            return this.hubConnectionState;","sourceCodeStart":1671,"sourceCodeEnd":1707,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java#L1671-L1707","documentation":"A RuntimeException thrown by ReconnectingConnectionState.getConnectionStateUnsynchronized when allowNull is false (i.e. the caller requires an active connection) but the internal ConnectionState field is null. This indicates the HubConnection is not active (never started or already stopped) and an internal caller required a live ConnectionState. It is an internal guard beneath the public APIs.","triggerScenarios":"An internal code path calls getConnectionStateUnsynchronized(false) after the ConnectionState has been cleared by stopConnection (setConnectionState(null)). For example, code paths in send/invoke/stream/state inspection that require a live connection reach this when the connection was never started or was stopped.","commonSituations":"Calling internal/derived behavior that touches ConnectionState after stop(). Reconnect logic inspecting state after teardown. Generally surfaces wrapped by higher-level 'not active' checks; seeing this raw message points to an internal caller (e.g. checkUploadStream or getReturnType) running after disconnect.","solutions":["Ensure the connection is CONNECTED (start() completed, not stopped) before any operation that needs ConnectionState.","Guard public-facing operations with getConnectionState() == CONNECTED checks.","If seen from upload-stream or return-type paths after disconnect, dispose those streams/callbacks on close."],"exampleFix":"// before: accessing connection internals after stop\nconnection.stop().blockingAwait();\nconnection.getTransport(); // internal path may hit getConnectionStateUnsynchronized(false) -> throws\n\n// after: only access while connected\nif (connection.getConnectionState() == HubConnectionState.CONNECTED) {\n    connection.getTransport();\n}","handlingStrategy":"validation","validationCode":"if (connection.getConnectionState() == HubConnectionState.CONNECTED) {\n    // safe to perform operations that require an active ConnectionState\n} else {\n    // skip or reconnect\n}","typeGuard":"boolean active = connection.getConnectionState() == HubConnectionState.CONNECTED;","tryCatchPattern":"// Internal guard; surface via state checks in user code.\ntry {\n    connection.invoke(\"x\").blockingAwait();\n} catch (RuntimeException e) {\n    if (e.getMessage().equals(\"Connection is not active.\")) {\n        // reconnect or defer the operation\n    } else { throw e; }\n}","preventionTips":["Gate every operation on getConnectionState() == CONNECTED.","Dispose upload streams and cancel timers on close so internal paths aren't hit post-disconnect.","Treat a raw 'Connection is not active.' as a sign of a lifecycle bug in your usage."],"tags":["signalr","java","internal","state-machine","lifecycle"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}