Skip to content

Commit

Permalink
fix(client): Connection locks dont increment on retries
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Apr 11, 2021
1 parent c0b171e commit 1e7bd97
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client.ts
Expand Up @@ -346,7 +346,9 @@ export function createClient(options: ClientOptions): Client {
waitForReleaseOrThrowOnClose: Promise<void>,
]
> {
locks++;
// locks increment only when not retrying because
// the same lock retries connect on abrupt closures
if (!retrying) locks++;

const [socket, throwOnClose] = await (connecting ??
(connecting = new Promise<Connected>((connected, denied) =>
Expand Down
37 changes: 37 additions & 0 deletions src/tests/client.ts
Expand Up @@ -983,6 +983,43 @@ describe('reconnecting', () => {
it.todo(
'should attempt reconnecting silently a few times before closing for good',
);

it('should lazy disconnect after retries when all subscriptions are completed', async () => {
const { url, ...server } = await startTServer();

const client = createClient({
url,
lazy: true, // behavior on lazy only
retryAttempts: Infinity, // keep retrying forever
retryWait: () => Promise.resolve(),
});

const sub = tsubscribe(client, {
query: 'subscription { ping }',
});

await server.waitForClient((client) => client.close());
await server.waitForClientClose();

await server.waitForClient((client) => client.close());
await server.waitForClientClose();

await server.waitForClient((client) => client.close());
await server.waitForClientClose();

// allow sub on the 3rd retry
await server.waitForOperation();

// dispose of the last and only subscription
sub.dispose();
await sub.waitForComplete();

// client should now leave
await server.waitForClientClose();

// and no clients should be left
expect(server.clients.size).toBe(0);
});
});

describe('events', () => {
Expand Down

0 comments on commit 1e7bd97

Please sign in to comment.