Skip to content

WebSocketChannel close code throws exception #1690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dukefirehawk opened this issue Jun 3, 2024 · 3 comments
Open

WebSocketChannel close code throws exception #1690

dukefirehawk opened this issue Jun 3, 2024 · 3 comments

Comments

@dukefirehawk
Copy link

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
@KevlarTheGreat
Copy link

Same problem on version 3.0.1

@mosuem mosuem transferred this issue from dart-archive/web_socket_channel Jan 22, 2025
@kashyap-5paisa
Copy link

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
Copy link

cade-2 commented Mar 1, 2025

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
Projects
None yet
Development

No branches or pull requests

5 participants