@actyx/pond: observeRegistry - when connection to actyx is severed the webapp becomes unresponsive

Hi,
our app has the following rough code:

<Pond
          onError={() => {
            console.error('pond error!')
            setInterval(() => window.location.reload(), 3000)
            return <PondConnectionTimeout />
          }}
          manifest={{
            appId: 'com.example.someId',
            displayName: 'someName',
            version: '0.9.48',
          }}
          connectionOpts={{
            onConnectionLost: () => {
              console.error('connection lost!')
              setInterval(() => window.location.reload(), 3000)
            },
          }}
          loadComponent={<PondConnectionTimeout />}
        >
          <Provider store={store}>
            <App />
          </Provider>
        </Pond>
export const App = (): JSX.Element => {
  const pond = usePond()
  observeRegistry(
    pond,
    errorRegistryFish, //any fish will do
    (state) => Array.from(state.uuids),
    mkErrorFish, // agian, anny fish will do
    (errorFishes) => {
      console.log('fishes', errorFishes)
    },
  )
  return <h1>App has Pond</h1>
}
export const errorRegistryFish: Fish<ErrorRegistryState, ErrorFishEvent> = {
  fishId: FishId.of(errorFishName, 'singleton', 1),
  where: errorRegistryFishNameFishTag,
  initialState: {
    uuids: List(),
  },
  onEvent,
  deserializeState,
}

when we kill the actyx process on that is connected to the pond, the tab of the browser running the app becomes unresponsive and does not reload as intended.

as soon as we remove the ‘observeRegistry’ call the reload works again.

react-pond and registry are both on version 3.0.0 , actyx is on version 2.8.1

Hi Frank,

sorry for the inconvenience, that sounds wrong, indeed.
However, a similar issue regarding error handling on lost Actyx WS connections was implemented in Pond v3.1.0: Actyx Pond Releases | Actyx Developer

I’d ask you to try the latest version 3.1.2, from what your description sounds like there is a good chance the issue does no longer occur.

Thanks!

Sadly we are already on 3.1.2.

Ok, it’s bound to be something else, then.
Let me see whether I can reproduce it tomorrow. Can’t make it today, unfortunately.

So, I’m able to reproduce the behavior, but I haven’t found out what causes it, yet.
When enabling debug in the console, we see that after the connection is lost, the pond keeps trying to update the registry. This happens over and over again and is most probably what causes the application to hang. It seems like the connection lost error is not handled correctly in this case.

browser.js:100 pond:error Connection lost with reason '', code 1006 +7ms
browser.js:100 pond:info ["error-fish","singleton",1] +6ms directly setting state. Num streams: 0 - Cycle: 0
browser.js:100 pond:error Connection lost with reason '', code 1006 +2ms
browser.js:100 pond:info ["error-fish","singleton",1] +2ms directly setting state. Num streams: 0 - Cycle: 0
...

I’ll need to pull in someone from R&D and let you know once we found the issue.
In the meantime, do you have a workaround you can use? Did you try with useRegistryFish from react-pond?

I found that turning on automatic reconnection in the pond’s connection options makes the issue disappear. Perhaps that might be a viable solution in your case?

 <Pond
      onError={errorHandler}
      manifest={{ ... }}
      connectionOpts={{
        onConnectionLost: connectionLostHandler,
        automaticReconnect: true // <- this one
      }}
      loadComponent={<PondConnectionTimeout />}
    >

Hey wwerner,
yes that worked! Thank you!

Are all parameters for connectionOps documented somewhere? I could not find them in the documentation of the pond.
Is there something like ‘onConnectionRegained’ ?

connectionOps are documented here: https://developer.actyx.com/docs/reference/pond/modules#actyxopts

I see that they are a bit hard to find, perhaps we’ll link to them from the corresponding How-To section.
Where would you have expected them?

Here under ‘Parameters’ @actyx-contrib/react-pond - v3.0.0 | @actyx-contrib/react-pond - v3.0.0

Right, I see.
The React-Pond just hands the connection options to Pond. I think the React-Pond docs have not been generated since the option was added, as there was no change in React-Pond since then.
I’ll see to it, thanks for the heads-up!

On that note, i’d really like a ‘onConnectionRegained’ option. That way we could easily add visual feedback for the connection state inside the app.

1 Like

Good idea!

I created a separate feature request here: Add `onConnectionEstablished` callback to `Pond`

Let’s discuss it there to keep different things separate. Please feel free to add your thoughts there.