Open
Description
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 commentedon Sep 9, 2024
Same problem on version 3.0.1
kashyap-5paisa commentedon Feb 11, 2025
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 commentedon 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