enisdenjo / graphql-ws

Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
https://the-guild.dev/graphql/ws
MIT License
1.75k stars 162 forks source link

handling "All Subscriptions Gone" #565

Closed iscekic closed 4 months ago

iscekic commented 5 months ago

I'm using the client in a nodejs env, like so:

state.client = createClient({
  url: wsUrl,
  webSocketImpl: WebSocketImpl,
  connectionParams: {
    headers: { /* ... */ },
  },
});

// some time later, this can happen multiple times concurrently
const subscription = state.client.iterate(/* ... */);

// these cleanup fns are called in some other places too
state.cleanupFns.set("some-id", () => {
  void subscription.return?.();
});

try {
  for await (const result of subscription) {
    // ...
  }
} catch (error) {
  // ...
}

void subscription.return?.();

state.cleanupFns.delete("some-id");

All seems to be working fine, however occasionally Sentry reports the following unhandled promise rejection: image

Judging from the line where it happens, looks like the client gets in a reconnect state, while all the subscriptions it has active are gone.

Is this something I should handle? If so, how?