{"record":{"id":"1fa9e77ac9008b08","repo":"EllanJiang/GameFramework","slug":"socket-is-not-active","errorCode":null,"errorMessage":"Socket is not active.","messagePattern":"Socket is not active\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Network/NetworkManager.NetworkChannelBase.cs","lineNumber":442,"sourceCode":"                    if (NetworkChannelError != null)\n                    {\n                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);\n                        return;\n                    }\n\n                    throw new GameFrameworkException(errorMessage);\n                }\n\n                if (!m_Active)\n                {\n                    string errorMessage = \"Socket is not active.\";\n                    if (NetworkChannelError != null)\n                    {\n                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);\n                        return;\n                    }\n\n                    throw new GameFrameworkException(errorMessage);\n                }\n\n                if (packet == null)\n                {\n                    string errorMessage = \"Packet is invalid.\";\n                    if (NetworkChannelError != null)\n                    {\n                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);\n                        return;\n                    }\n\n                    throw new GameFrameworkException(errorMessage);\n                }\n\n                lock (m_SendPacketPool)\n                {\n                    m_SendPacketPool.Enqueue(packet);\n                }","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Network/NetworkManager.NetworkChannelBase.cs#L424-L460","documentation":"Send<T> verifies m_Active after checking the socket exists. m_Active is false when the socket has been created but the channel was closed/disposed or never fully activated, so the packet cannot be enqueued. GameFramework throws GameFrameworkException (or fires NetworkChannelError with NetworkErrorCode.SendError).","triggerScenarios":"Calling Send after the channel was closed (Dispose/shutdown sets m_Active false); sending on a channel whose connection dropped and was deactivated; calling Send concurrently with channel close.","commonSituations":"App keeps a stale channel reference after the server closed the connection and tries to send the next message; sending during scene teardown while the network component is being destroyed; send/recv races around Dispose.","solutions":["Listen to NetworkChannelClosed/disconnect events and stop sending once the channel is closed; reconnect before sending again.","Check that the channel is active (or your own connected flag) before each Send call.","Recreate the channel with NetworkManager.CreateNetworkChannel and Connect again if it was closed.","Guard Send calls against concurrent shutdown (do not send from other threads while disposing)."],"exampleFix":"// before\nchannel.Send(chatPacket); // throws after close\n// after\nif (isConnected) { channel.Send(chatPacket); } else { Reconnect(); }","handlingStrategy":"validation","validationCode":"public static bool CanSend(INetworkChannel ch) => ch != null && connectedChannels.Contains(ch); // remove on NetworkChannelClosed","typeGuard":"public static bool IsActive(INetworkChannel ch) => ch != null && !closedChannels.Contains(ch);","tryCatchPattern":"try { channel.Send(packet); } catch (GameFrameworkException ex) when (ex.Message == \"Socket is not active.\") { ReconnectAndRequeue(packet); }","preventionTips":["Unsubscribe send logic on NetworkChannelClosed","Treat disconnects as terminal for the channel object; reconnect with a new channel","Never send from background threads while the channel may be disposing","Centralize sends behind a wrapper that checks connection state"],"tags":["network","socket","invalid-state","gameframework"],"backgroundTag":"invalid-state-transition","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}