Skip to content

net472: a server close with 1012 ends terminal sockets in a transport exception #934

Closed

Description

@Blind-Striker

On .NET Framework, a terminal socket that the server closes with code 1012 ends in a transport exception instead of a peer closure. .NET 10 and .NET 11 see a clean close.

What happens

opencode closes every socket that borrows a location with 1012 location shut down when that location shuts down: a reload, a VCS init or a debug eviction (packages/server/src/handlers/pty-socket.ts:35-46 at the pinned v2.3.0). The PTY and persistent-PTY doors hold such sockets.

On .NET Framework, the SDK's terminal socket is ClientWebSocket (src/OpenCode.Sdk/Internal/Terminal/ClientTerminalWebSocket.cs, ReceiveAsync). There, a received close frame with 1012 does not arrive as a close. It throws:

System.Net.WebSockets.WebSocketException: Invalid data format for the specific protocol operation
  WebSocketErrorCode = NativeError, NativeErrorCode = HResult = 0x83760002, socket State = Aborted

So a PTY session on net472 ends with a transport exception where net10.0 and net11.0 end with a peer closure. Client-hosted MCP is not affected: it retries after both.

Evidence

A raw TCP server wrote the 101 handshake and one close frame by hand, so no server-side WebSocket stack validated the code. The client was ClientWebSocket, run with one ReceiveAsync:

Close code sent .NET Framework 4.8.10008 .NET 10.0.14
1000 clean close, code and reason intact clean close
1011 clean close clean close
1012 WebSocketException, 0x83760002, Aborted clean close
1013 same exception clean close
1014 same exception clean close
4000 clean close clean close

Windows' native WebSocket component, which .NET Framework's ClientWebSocket and HttpListener use, rejects the close codes that were registered with IANA after RFC 6455 (1012–1014). On .NET 10, HttpListener also refuses to send 1012, with the same error.

Options

  • (a) On .NET Framework only, map exactly this receive failure (WebSocketError.NativeError with native code 0x83760002) to a peer closure whose close code is unknown. It is narrow and recognisable, but the code and reason are lost.
  • (b) Keep the behaviour, and document it as a .NET Framework platform limit in docs/architecture/client-runtime.md.

Recommendation: (a) plus a canon line that names the limit and the mapping. (a) is a platform-specific mapping, so the choice is the maintainer's.

Found while writing the client-hosted MCP live tests. Refs #529

Activity

  1. added
    bug
    needs-triage
    on Nov 16, 2026
  2. Blind-Striker commented on Nov 16, 2026

    @Blind-Striker
    CollaboratorAuthor

    Decision: option (b). Document the .NET Framework behaviour, and add no mapping and no new transport.

    Option (c), a managed WebSocket on .NET Framework, was researched and dropped:

    • Microsoft's System.Net.WebSockets.WebSocketProtocol package (5.1.3, net462/netstandard2.0) carries the .NET 5-era managed protocol code. Its close-status validation accepts only 1000-1003 and 1007-1011. It closes with ProtocolError and throws on 1012-1014, the same failure as today. The 1012-1014 acceptance came with dotnet/runtime #83827 (.NET 8) and never reached that package. The package's own notes also call it obsolete.
    • Getting a clean 1012 on .NET Framework would mean vendoring .NET 8+'s ManagedWebSocket (about 2,000 lines) plus our own client handshake, and owning that protocol stack. That cost is out of proportion for one close code on one target.

    Done-when: client-runtime.md states that on .NET Framework a server close with 1012, 1013 or 1014 surfaces as a WebSocketException (native error 0x83760002) and the socket is Aborted, while .NET 10+ reports the close normally. The terminal guide repeats it where it describes closes.

  3. added this to the 1.x milestone on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions