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.

Subscriptions do not throw error on websocket failure

See original GitHub issue

Describe the bug When subscribing to AppSync updates through AWS Amplify, undefined websocket errors do not invoke the error callback. If a websocket is unable to connect and returns undefined, an error is logged in the console but the subscription’s error callback is not invoked.

To Reproduce This occurs when the webapp is connected to a network that blocks or inhibits websocket connections, such as some proxies and corporate networks.

Expected behavior When an error occurs such as a network disconnection, the error callback should be invoked. Currently a network disconnection invokes the error callback but an undefined websocket connection does not.

Desktop:

  • OS: Windows 7, Windows 10, and MacOS X
  • Browser: Chrome 73, IE 11, and Edge 15

Smartphone:

  • Device: iPhone X
  • OS: iOS 12.2
  • Browser: Safari

Sample code

API.graphql(
  graphqlOperation(subscriptions.mutatedItem, { item_id: item_id })
).subscribe({
  error: (err) => console.log("Network disconnected"),
  next: (eventData) => updateItems(eventData)
});

Console Output

paho-mqtt.js:1128 WebSocket connection to ‘wss://**************-ats.iot.us-west-2.amazonaws.com/mqtt?..’ failed: Error during WebSocket handshake: Unexpected response code: 400 S._doConnect @ paho-mqtt.js:1128

Uncaught (in promise) Object errorCode: 7 errorMessage: “AMQJS0007E Socket error:undefined.” invocationContext: undefined

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
justinjoyncommented, Feb 18, 2020

Any update on this? I always get this error when trying to subscribe to a topic after internet is restored.

     "errorCode":7,
     "errorMessage":"AMQJS0007E Socket error:undefined."
1reaction
borch84commented, May 7, 2019

I let my application run for sometime and I watched messages console. Then I reloaded my web browser and I got this:

WARN] 12:06.456 MqttOverWSProvider - bd35da34-d348-44ae-8da7-31456c485019 {
  "errorCode": 8,
  "errorMessage": "AMQJS0008I Socket closed.",

I did not get the undefined socket error and the application still shows messages from the topic. It looks like the reconnection is happening internally. I wonder if it could useful that MqttOverWSProvider informs about any reconnection issue to the user?. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle WebSocket errors - Apollo GraphQL Docs
This code has to be implemented in different places; The attempt is tied to the collector lifecycle, there is no way to reset...
Read more >
WebSocket: error event - Web APIs | MDN
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
Read more >
WebSocket connection failed: Error during ... - Stack Overflow
Problem solved! I just figured out how to solve the issue, but I would still like to know if this is normal behavior...
Read more >
WebSockets - Handling Errors
WebSockets - Handling Errors, Once a connection has been established between the client and the server, an open event is fired from the...
Read more >
Error with WebSocket - Microsoft Q&A
Server/' failed: Error in connection establishment: net::ERR_CONNECTION_RESET. I have no other programs or services running that could be ...
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