question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: WebSocket is already in CLOSING or CLOSED state

See original GitHub issue

After switching from subscriptions-transport-ws in Apollo client, there is always error WebSocket is already in CLOSING or CLOSED state after initialization in browser console.

Further Information

const wsLink = new GraphQLWsLink(
	createClient({
		url: 'ws://localhost:4000',
		connectionParams: async () => ({
			credentials: 'include',
			authorization: await getAuthToken(),
		}),
	})
)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Mangattcommented, Mar 14, 2022

Thanks, 5.6.3 have solved the problem.

0reactions
enisdenjocommented, Mar 13, 2022

Inspecting the callstack and taking a hint from your further comment - I suspect that the connectionParams is taking too long to resolve, causing the server to kick off the client respecting the connectionInitWaitTimeout.

To solve it, simply increase the timeout on the server or speed up the connectionParams.

The fix released in v5.6.3 stops execution after connectionParams if the connection was closed while waiting. Previously, the client was trying to send a message afterwards regardless, leading to the error in the browser’s console.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How to catch and deal with "WebSocket is already ...
i resolved this by checking the readystate property; if it equals to 3, close and reinitialize the websocket connection. then do a while...
Read more >
WebSocket is already in CLOSING or CLOSED state. ERROR
WebSocket is already in CLOSING or CLOSED state means that the connection has been disconnected and data cannot be sent through this connection....
Read more >
WebSocket is already in CLOSING or CLOSED state.
The log message seems to indicate that the client side javascript is attempting to close the socket when in fact the server has...
Read more >
WebSocket - The Modern JavaScript Tutorial
It responds with “Hello from server, John”, then waits 5 seconds and closes the connection. So you'll see events open → message →...
Read more >
How to fix error: WebSocket is already in CLOSING or ...
How to fix error: WebSocket is already in CLOSING or CLOSED state · Example 1: · Example 2: · Example 3:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found