You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Websocket connection doesn't reconnect after a device wakes up from sleep #6149
Browsers you attempted to reproduce this bug on (the more the merrier): Chrome, Brave
Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes
Actual behavior
I am seeing the following errors in a mobile and a desktop browser after the devices wake up from short sleep when accessing the LiveView (vsn 1.0.5) server:
Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was receivedUnderstand this errorAI
app-2b0afc197cdceeb5c92611615d031f1a.js?vsn=d:28 WebSocket connection to 'wss://********.com/live/websocket?_csrf_token=MRIhNjQqCyQAACBjFSgxDi8XFXsOBDU9rwDdEAnVgvp1_lBaXyG8ZsFb&_track_static%5B0%5D=https%3A%2F%2F********.com%2Fassets%2Fapp-e7baf904e1e50202d94c8a4610601ef5.css%3Fvsn%3Dd&_track_static%5B1%5D=https%3A%2F%2F********.com%2Fassets%2Fapp-2b0afc197cdceeb5c92611615d031f1a.js%3Fvsn%3Dd&_mounts=2&_mount_attempts=0&_live_referer=https%3A%2F%2F********.com%2Fapp%2Forg%2Fuhost&vsn=2.0.0' failed:
This is observed on a desktop and mobile phones.
Expected behavior
A Websocket should reconnect when a device wakes up and the browser still stays on a page with a LiveView that had an active socket before the device went to sleep.
I can confirm that the issue is steadily reproduciable in various browsers (tried Chrome, Brave, Safari), without any extensions, on desktop, Android, iPhone devices.
Shouldn't this invocation of new socket transport be trapped in a try/catch block? Maybe this is the culprit that breaks the script and fails to schedule a reconnection timer?
Error:
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28 WebSocket connection to 'wss://*********.com/live/websocket?_csrf_token=WjwuCHQ-NDN_GSYlTRARAAQFCXg…js%3Fvsn%3Dd&_mounts=1&_mount_attempts=0&_live_referer=undefined&vsn=2.0.0' failed:
That code in Phoenix has always looked like this and seemed to work just fine. Can you maybe try older Phoenix + LiveView versions to see if those make a difference?
Same result with LiveView 1.0.5. Is this a Phoenix bug or the LiveView?
I enabled the socket's debug mode, and here are more details. It looks like the attempt to create a reconnect timer throws an exception, and the new timer is never getting scheduled.
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28 WebSocket connection to 'wss://*******.com/live/websocket?_csrf_token=QxEcZBQfJDUNfRJjajcYXj0tMn0…js%3Fvsn%3Dd&_mounts=0&_mount_attempts=0&_live_referer=undefined&vsn=2.0.0' failed:
0
transportConnect
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
1
connect
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
2
(anonymous)
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
3
(anonymous)
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
4
waitForSocketClosed
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
5
(anonymous)
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
6
waitForBufferDone
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
7
teardown
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
8
(anonymous)
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28
9
(anonymous)
@
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:27
Top two frames in the stack that show the origin of the exception:
connect(e){e&&(console&&console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"),this.params=fo(e)),!this.conn&&(this.longPollFallbackMs&&this.transport!==ho ? this.connectWithFallback(ho,this.longPollFallbackMs) : this.transportConnect())// <-- Here}
Activity
SteffenDE commentedon Mar 24, 2025
Hey @saleyn,
I've never seen that error before, but a quick search indicates that this is probably caused by a browser extension (https://stackoverflow.com/questions/72494154/a-listener-indicated-an-asynchronous-response-by-returning-true-but-the-messag). Can you please try in a private browser window - or just in general with extensions disabled?
saleyn commentedon Mar 25, 2025
I can confirm that the issue is steadily reproduciable in various browsers (tried Chrome, Brave, Safari), without any extensions, on desktop, Android, iPhone devices.
saleyn commentedon Mar 26, 2025
Shouldn't this invocation of new socket transport be trapped in a try/catch block? Maybe this is the culprit that breaks the script and fails to schedule a reconnection timer?
Error:
SteffenDE commentedon Mar 26, 2025
That code in Phoenix has always looked like this and seemed to work just fine. Can you maybe try older Phoenix + LiveView versions to see if those make a difference?
saleyn commentedon Mar 26, 2025
I'll try. Though is there a reason why that code block above doesn't trap the exception?
SteffenDE commentedon Mar 26, 2025
I assume it's because the only case according to the spec where it should throw an exception is a SyntaxError: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket#exceptions. Any connection error should be handled by the error event.
saleyn commentedon Mar 27, 2025
Same result with LiveView 1.0.5. Is this a Phoenix bug or the LiveView?
I enabled the socket's debug mode, and here are more details. It looks like the attempt to create a reconnect timer throws an exception, and the new timer is never getting scheduled.
app-2b0afc197cdceeb5…d031f1a.js?vsn=d:28 WebSocket connection to 'wss://*******.com/live/websocket?_csrf_token=QxEcZBQfJDUNfRJjajcYXj0tMn0…js%3Fvsn%3Dd&_mounts=0&_mount_attempts=0&_live_referer=undefined&vsn=2.0.0' failed:
Top two frames in the stack that show the origin of the exception:
Frame0:
Frame1:
Frame2:
Frame3:
SteffenDE commentedon Mar 28, 2025
The code responsible for reconnects is in Phoenix: https://github.com/phoenixframework/phoenix/tree/main/assets/js/phoenix
I tried to reproduce this with a Ubuntu VM, but wasn't able to :(
saleyn commentedon Mar 28, 2025
Should I move this issue to the Phoenix repo?
Stop reconnecting when page is hidden
Stop reconnecting when page is hidden (phoenixframework#6534)
Stop reconnecting when page is hidden (phoenixframework#6534)