egametang/ET · error · Exception

socket error: {e.LastOperation}

Error message

socket error: {e.LastOperation}

What it means

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.

Source

Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Network/TService.cs:78

			this.acceptor.Listen(1000);
			
			this.AcceptAsync();
		}

		public override IPEndPoint GetBindPoint()
		{
			return this.acceptor.LocalEndPoint as IPEndPoint;
		}

		private void OnComplete(object sender, SocketAsyncEventArgs e)
		{
			switch (e.LastOperation)
			{
				case SocketAsyncOperation.Accept:
					this.Queue.Enqueue(new TArgs() {SocketAsyncEventArgs = e});
					break;
				default:
					throw new Exception($"socket error: {e.LastOperation}");
			}
		}

		private void OnAcceptComplete(SocketError socketError, Socket acceptSocket)
		{
			if (this.acceptor == null)
			{
				return;
			}

			if (socketError != SocketError.Success)
			{
				Log.Error($"accept error {socketError}");
				this.AcceptAsync();
				return;
			}

			try

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Confirm only accept-related SocketAsyncEventArgs use this OnComplete handler.
  2. Log and ignore unexpected operations instead of crashing the accept loop.
  3. Audit the Completed subscription wiring for the acceptor vs channels.

Example fix

// before
default: throw new Exception($"socket error: {e.LastOperation}");
// after
default: Log.Error($"unexpected socket op on acceptor: {e.LastOperation}"); break;
Defensive patterns

Strategy: type-guard

Validate before calling

null

Type guard

static bool IsExpectedAcceptorOp(SocketAsyncOperation op) => op == SocketAsyncOperation.Accept;

Try / catch

null

Prevention

When it happens

Trigger: A SocketAsyncEventArgs wired with the wrong operation reaches OnComplete, or a Send/Receive event was accidentally attached to the acceptor's handler.

Common situations: 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.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/4c137a6caf500048. Report an issue: GitHub.