Skip to content

wasm: Close with codes other than 1000 throws, so CloseNow never closes #575

Open

Description

@0pcom

In the js/wasm build, Conn.Close passes the code straight to the browser's WebSocket.close, which only accepts 1000 and 3000-4999 and throws InvalidAccessError for anything else. This package closes with 1001 (CloseNow), 1008 (read or dial context done), 1009 (read limit) and 1011 (write error), so all of those return an error and leave the socket open. Under TinyGo the throw is not recovered, so the program panics.

To reproduce, dial any server and call c.CloseNow(). In Chromium it returns:

failed to close WebSocket: JavaScript error: Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999. 1001 is neither.

A fix is to send 1000 to the browser for the codes it rejects. I have a PR for it.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions