ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

usePresence error - Uncaught (in promise) Error: Connection closed

Open bookercodes opened this issue 10 months ago • 4 comments

When using usePresence, if I reload the page, I see the following error (with preserve log on)

ably.js:260 Uncaught (in promise) Error: Connection closed
    at _ErrorInfo.fromValues (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:260:34)
    at Object.closed (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:3697:27)
    at WebSocketTransport.close (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:3749:52)
    at _ConnectionManager.closeImpl (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:5113:42)
    at _ConnectionManager.requestState (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:4898:12)
    at eval (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:4197:16)

I wonder if maybe ably-js is trying to send an event like "leave" but the connection is already closed? Possibly related to this LOC?

The code to reproduce is very simple:

import { usePresence } from "ably/react"

const WhosOnlineList = ({ channelName }) => {

  usePresence(channelName, { fullName: Math.random() })


  return null
}
export default WhosOnlineList

Why does this matter?

It might not. I don't think you can technically be "present" on a channel if the connection has closed, but I'd like to understand the error better in case I should be structuring my React component differently.

Thank you!

┆Issue is synchronized with this Jira Task by Unito

bookercodes avatar Apr 26 '24 15:04 bookercodes

I have the exact same error, except I don't use the hook. The sample code I use is in the comment - https://github.com/ably/ably-js/issues/1565#issuecomment-2078903030.

nikitadubyk avatar Apr 29 '24 07:04 nikitadubyk

Hello @bookercodes , @nikitadubyk !

Thank you for reporting this and providing steps to reproduce. We're going to investigate this and get back with an update as soon as possible!

VeskeR avatar May 01 '24 12:05 VeskeR

Hey @bookercodes , @nikitadubyk !

I was able to reproduce the issue with the provided code sample. I'm currently looking into its cause.

VeskeR avatar May 02 '24 13:05 VeskeR

Same errors on page reload after updating to v2.

Elmosh avatar May 04 '24 16:05 Elmosh

Hello, I am working on a tutorial I'm aiming to publish this week and keep getting this error. Can it safely be ignored or am I doing something wrong?

bookercodes avatar May 08 '24 16:05 bookercodes

Hey @bookercodes ! You are not doing anything wrong; this is an issue on the ably-js side. We're planning to release a fix for it this week.

In the meantime, since this error occurs on page reload and essentially tries to close a connection a second time after it's already been closed, you can safely ignore it for now. The only real downside is that these errors might appear in your log monitoring tools.

VeskeR avatar May 09 '24 12:05 VeskeR

This has been fixed in https://github.com/ably/ably-js/pull/1761 and will be released in the next patch version for ably-js package.

VeskeR avatar May 29 '24 00:05 VeskeR

Hey, the fix for this issue has been released in 2.1.0 release of ably-js. Thank you for reporting this issue!

VeskeR avatar Jun 03 '24 23:06 VeskeR

Great, thank you, I will update!

bookercodes avatar Jun 05 '24 21:06 bookercodes