Skip to content
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

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

Open
wowafelyk opened this issue Nov 13, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@wowafelyk
Copy link

Which packages are you using?

stream_chat_flutter

On what platforms did you experience the issue?

Web

What version are you using?

stream_chat_flutter: ^6.10.0

What happened?

We receive multiple errors via sentry with next decription:
InvalidAccessError: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1001 is neither

Application doesn't use WebSocket directly. Only possible dependency are via StreamChat.

Steps to reproduce

Steps ara mostly unknown except: 
All occurrences happen before login. It could be possible users where logged out with time out earlier.

Supporting info to reproduce

No response

Relevant log output

We received multiple errors about WeSocket close failed.
Stack trace:
1) 
`minified:a93: InvalidAccessError: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1001 is neither.
  at dartProgram(main.dart.js:120:6)
  at A.fl_(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1391:46)
  at _CustomZone.run(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1300:34)
  at _CustomZone.runGuarded(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1209:7)
  at _BufferingStreamSubscription._sendDone.sendDone(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:392:7)
  at _BufferingStreamSubscription._sendDone(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:402:7)
  at _BufferingStreamSubscription._close(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:291:7)
  at _SyncStreamControllerDispatch._sendDone(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:792:19)
  at _StreamController.stream.a4W.prototype.TD(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:647:7)
  at _StreamController.stream.a4W.prototype.ai(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:640:5)`
2) 

minified:a9b: InvalidAccessError: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1001 is neither.
  at HtmlWebSocketChannel._listen.<anonymous function>(../../../../.pub-cache/hosted/pub.dev/web_socket_channel-2.4.0/lib/html.dart:134:9)
  at A.fl0(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1391:46)
  at _CustomZone.runUnary(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1308:12)
  at _CustomZone.runGuarded(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1210:7)
  at _BufferingStreamSubscription._sendDone.sendDone(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:393:7)
  at _BufferingStreamSubscription._guardCallback(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:411:8)
  at _BufferingStreamSubscription._close(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:293:7)
  at dartProgram(main.dart.js:793:3)
  at _StreamController.stream.a52.prototype.Tc(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:649:7)
  at _StreamController.stream.a52.prototype.ag(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:641:5)
minified:a9b: InvalidAccessError: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1001 is neither.
  at HtmlWebSocketChannel.<anonymous function>(../../../../.pub-cache/hosted/pub.dev/stream_channel-2.1.1/lib/src/guarantee_channel.dart:20:32)
  at A.fl0(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1391:46)
  at _CustomZone.run(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1300:34)
  at _CustomZone.runGuarded(org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1209:7)
  at _BufferingStreamSubscription._sendDone.sendDone(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:392:7)
  at _BufferingStreamSubscription._sendDone(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:402:7)
  at _BufferingStreamSubscription._close(org-dartlang-sdk:///dart-sdk/lib/async/stream_impl.dart:291:7)
  at _SyncStreamControllerDispatch._sendDone(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:792:19)
  at _StreamController.stream.a52.prototype.Td(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:647:7)
  at _StreamController.stream.a52.prototype.ag(org-dartlang-sdk:///dart-sdk/lib/async/stream_controller.dart:640:5)


### Flutter analyze output

_No response_

### Flutter doctor output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
@wowafelyk wowafelyk added the bug Something isn't working label Nov 13, 2023
@followthemoney1
Copy link

hey guys, any updates on it?

@esarbanis
Copy link
Contributor

Hey @wowafelyk thanks for opening this issue!

As you can imagine this is hard to reproduce, but it is on our radar now.

@followthemoney1 did you have the same error? Do you have any specific info that can help us reproduce it?

@followthemoney1
Copy link

@esarbanis yeah same error here, I don't have specific info but I cqn tell you app Id in get stream which we are using so you can track maybe

Copy link

This issue is stale because it has been open for 20 days with no activity.

@github-actions github-actions bot added the Stale label Feb 22, 2024
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 29, 2024
@ejlevin1
Copy link

ejlevin1 commented May 3, 2024

I'm experiencing this issue as well. Has this been looked at? It is pretty consistently happening on the web.

@xiprox
Copy link

xiprox commented May 8, 2024

We seem to be getting thousands of events due to this issue, which depletes our quota on Sentry.

@Jan-Stepien
Copy link

We seem to be getting thousands of events due to this issue, which depletes our quota on Sentry.

Same case

@billdacat
Copy link

I am also experiencing this issue.

Invalid argument(s): Invalid argument: 1001, close code must be 1000 or in the range 3000-4999

utils.dart in checkCloseCode at line 10:5 within web_socket

@billdacat
Copy link

It appears because status.goingAway is used, which is 1001:

dart-lang/http#1203

Please see the docs here: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
It says 1000 - normal closure, 1001 - going away, 1002 - Protocol error, and so on.

so as soon as a user goes away, it throws the closure with 1001, in websocket.dart:

if (_webSocketChannel != null) {
_unsubscribeFromWebSocketChannel();
_webSocketChannel?.sink
.close(_manuallyClosed ? status.normalClosure : status.goingAway);
_webSocketChannel = null;
}

From https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#code:

If unspecified, a close code for the connection is automatically set: to 1000 for a normal closure, or otherwise to another standard value in the range 1001-1015 that indicates the actual reason the connection was closed.

If specified, the value of this code parameter overrides the automatic setting of the close code for the connection, and instead sets a custom code. The value must be an integer: either 1000, or else a custom code of your choosing in the range 3000-4999. If you specify a code value, you should also specify a reason value.

--

Reading that, you aren't supposed to specify status.goingAway explicitly, and just leave it unspecified? Not too familiar with this, just parsing it -- otherwise it seems if specified, a custom status (maybe 3001) for status.goingAway should be used instead.

@ihijazi
Copy link

ihijazi commented Feb 6, 2025

Experiencing the same here. Hopefully this get looked into

@xsahil03x xsahil03x reopened this Feb 10, 2025
@github-actions github-actions bot removed the Stale label Feb 10, 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.

@river2202
Copy link

river2202 commented Feb 14, 2025

still seeing this in stream_chat_flutter: ^8.3.0 / flutter 3.24.

Is there update on this? will stream_chat_flutter: 9.2 / flutter 3.27/9 fix this issue?

this happened on iPad / iOS for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests