{"record":{"id":"4c137a6caf500048","repo":"egametang/ET","slug":"socket-error-e-lastoperation","errorCode":null,"errorMessage":"socket error: {e.LastOperation}","messagePattern":"socket error: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Network/TService.cs","lineNumber":78,"sourceCode":"\t\t\tthis.acceptor.Listen(1000);\n\t\t\t\n\t\t\tthis.AcceptAsync();\n\t\t}\n\n\t\tpublic override IPEndPoint GetBindPoint()\n\t\t{\n\t\t\treturn this.acceptor.LocalEndPoint as IPEndPoint;\n\t\t}\n\n\t\tprivate void OnComplete(object sender, SocketAsyncEventArgs e)\n\t\t{\n\t\t\tswitch (e.LastOperation)\n\t\t\t{\n\t\t\t\tcase SocketAsyncOperation.Accept:\n\t\t\t\t\tthis.Queue.Enqueue(new TArgs() {SocketAsyncEventArgs = e});\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Exception($\"socket error: {e.LastOperation}\");\n\t\t\t}\n\t\t}\n\n\t\tprivate void OnAcceptComplete(SocketError socketError, Socket acceptSocket)\n\t\t{\n\t\t\tif (this.acceptor == null)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (socketError != SocketError.Success)\n\t\t\t{\n\t\t\t\tLog.Error($\"accept error {socketError}\");\n\t\t\t\tthis.AcceptAsync();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Network/TService.cs#L60-L96","documentation":"TService.OnComplete dispatches SocketAsyncEventArgs completions by LastOperation. The acceptor only expects Accept completions; any other operation (Receive/Send/Disconnect) is treated as an impossible state and throws.","triggerScenarios":"A SocketAsyncEventArgs wired with the wrong operation reaches OnComplete, or a Send/Receive event was accidentally attached to the acceptor's handler.","commonSituations":"A reuse/programming bug in the socket wiring, or a framework regression where a channel's args bubble up to the acceptor's Completed handler.","solutions":["Confirm only accept-related SocketAsyncEventArgs use this OnComplete handler.","Log and ignore unexpected operations instead of crashing the accept loop.","Audit the Completed subscription wiring for the acceptor vs channels."],"exampleFix":"// before\ndefault: throw new Exception($\"socket error: {e.LastOperation}\");\n// after\ndefault: Log.Error($\"unexpected socket op on acceptor: {e.LastOperation}\"); break;","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"static bool IsExpectedAcceptorOp(SocketAsyncOperation op) => op == SocketAsyncOperation.Accept;","tryCatchPattern":"null","preventionTips":["Only attach the acceptor's Completed handler to accept args.","Log unexpected ops instead of crashing the accept loop.","Audit args wiring when adding new socket operations."],"tags":["network","tcp","socket","csharp"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}