Skip to content

WebSocketChannel close code throws exception #1690

Open
@dukefirehawk

Description

@dukefirehawk

For version 3.0.0, when calling close with a status argument, it throws an exception. Only status.normalClosure which is 1000 works. The rest of the status code seems like not being mapped into the 3000-4999 range which can cause the exception to be thrown.

Code snippet

    var channel = IOWebSocketChannel.connect(...);
    ...
    channel.sink.close(status.goingAway);
    

Exception

  Invalid argument(s): Invalid argument: 1001, close code must be 1000 or in the range 3000-4999
  package:web_socket/src/utils.dart 10:5                             checkCloseCode
  package:web_socket/src/io_web_socket.dart 108:5                    IOWebSocket.close
  package:web_socket_channel/adapter_web_socket_channel.dart 112:27  new AdapterWebSocketChannel.<fn>.<fn>
  package:stream_channel                                             _GuaranteeSink.close
  package:async/src/delegate/stream_sink.dart 47:27                  DelegatingStreamSink.close
  package:web_socket_channel/adapter_web_socket_channel.dart 147:18  _WebSocketSink.close

Activity

KevlarTheGreat

KevlarTheGreat commented on Sep 9, 2024

@KevlarTheGreat

Same problem on version 3.0.1

kashyap-5paisa

kashyap-5paisa commented on Feb 11, 2025

@kashyap-5paisa

The 1001 - Going Away status is typically reserved for server-side closures.
If a client wants to gracefully close the connection and notify the backend of a specific reason, it’s better to use 1000 - Normal Closure or a 3000-3999 code, provided both teams maintain a record of what each code represents.

cade-2

cade-2 commented on Mar 1, 2025

@cade-2

same here version 3.0.2

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Invalid argument(s): Invalid argument: 1001, close code must be 1000 or in the range 3000-4999
E/flutter ( 3772): #0 checkCloseCode (package:web_socket/src/utils.dart:10:5)
E/flutter ( 3772): #1 IOWebSocket.close (package:web_socket/src/io_web_socket.dart:108:5)
E/flutter ( 3772): #2 new AdapterWebSocketChannel.. (package:web_socket_channel/adapter_web_socket_channel.dart:112:27)
E/flutter ( 3772): #3 _RootZone.runGuarded (dart:async/zone.dart:1597:10)
E/flutter ( 3772): #4 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:419:13)
E/flutter ( 3772): #5 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:429:7)
E/flutter ( 3772): #6 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:318:7)
E/flutter ( 3772): #7 _SyncStreamControllerDispatch._sendDone (dart:async/stream_controller.dart:785:19)
E/flutter ( 3772): #8 _StreamController._closeUnchecked (dart:async/stream_controller.dart:640:7)
E/flutter ( 3772): #9 _StreamController.close (dart:async/stream_controller.dart:633:5)
E/flutter ( 3772): #10 new GuaranteeChannel.. (package:stream_channel/src/guarantee_channel.dart:55:31)
E/flutter ( 3772): #11 _RootZone.runGuarded (dart:async/zone.dart:1597:10)
E/flutter ( 3772): #12 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:419:13)
E/flutter ( 3772): #13 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:429:7)
E/flutter ( 3772): #14 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:318:7)
E/flutter ( 3772): #15 _SyncStreamControllerDispatch._sendDone (dart:async/stream_controller.dart:785:19)
E/flutter ( 3772): #16 _StreamController._closeUnchecked (dart:async/stream_controller.dart:640:7)

how to solve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @KevlarTheGreat@dukefirehawk@mosuem@kashyap-5paisa@cade-2

        Issue actions

          WebSocketChannel close code throws exception · Issue #1690 · dart-lang/http