8000 Net.Socket + Net.HTTP.WebSocket crash erlc with a close/closed? collision — blocks WebSocket routes on a real HTTP server · Issue #360 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Net.Socket + Net.HTTP.WebSocket crash erlc with a close/closed? collision — blocks WebSocket routes on a real HTTP server #360

Closed

Description

@akoskovacs

Any program that imports both Net.Socket and Net.HTTP.WebSocket fails at erlc with a name-collision crash between Net.Socket.TCP's close/closed? and Net.HTTP.WebSocket.Connection's own close/closed? — before running any code, and even when the program never calls either.

Repro

using Net.Socket
using Net.HTTP.WebSocket

main do
  IO.printLine("compiled fine")
end
/tmp/kex_.../Kex.Net.Socket.TCP.core: internal error in pass beam_ssa_throw:
exception error: {key_exists,{b_local,{b_literal,close},2}}
  in function  gb_trees:insert_1/4 (gb_trees.erl:363)
  ...
error: erlc failed

This is the same class of bug as #348 (two declarations sharing a name colliding at the erlc/SSA level), except both sides here are in kex's own stdlib, not application code, and — worse — there's no way for a caller to fix it by renaming anything.

What makes it worse than #348: the trigger is fragile and hard to predict

Adding Net.HTTP's Client to scope alongside the other two imports makes the minimal case above compile and run:

using Net.HTTP.WebSocket
using Net.HTTP, only: [Router, Route, Server, Headers, Response, Client]  # Client added
using Net.Socket

main do
  let router = Router { routes: [] }
  let server = Server.start(TCP.Endpoint.loopback(Net.Port.from(0).try), router).try
  IO.printLine("port ${server.localAddress.port.value}")
end

But this is not a reliable workaround — it stops helping once more of a real program's module graph is involved. I hit this trying to add a ws (WebSocket route) DSL function to kexhq/rodolfo: the Client-import trick fixed a 7-line standalone repro, but the identical trick applied to Rodolfo itself (which also uses Net.Markup, Net.HTTP.Response re-exports, URI, etc.) did not — same crash, different colliding name (closed? instead of close) depending on exactly what else was compiled alongside it. Worse: merely declaring the WebSocket-route support in Rodolfo's source — without any application ever using it, without a single ws route declared in the whole program — was enough to crash Rodolfo's entire existing test suite, none of which touches WebSocket at all. The bug isn't gated on runtime use; it's gated on what's reachable in the compiled module graph.

Expected

Net.Socket and Net.HTTP.WebSocket should compile together regardless of what else is or isn't also imported — this blocks building any real HTTP server that also wants to accept WebSocket connections on the same program, which is the ordinary case (a web framework layering ws routes over its existing Net.Socket-based HTTP server).

Environment

kex 0.4.0-beta.3, cc5c195 — a fresh, isolated build of main, includes #359 (#354's fix) and #355 (#345's server-upgrade support). Found immediately after #345 shipped, trying to build on it.

Activity

  1. added
    BugSomething isn't working
    ImportantNeeds attention sooner rather than later
    on Sep 16, 2026
  2. added this to the 0.4.0 milestone on Sep 16, 2026
  3. added a commit that references this issue on Sep 16, 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

    BEAMBugSomething isn't workingImportantNeeds attention sooner rather than later

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0