Skip to content

Commit

Permalink
fix: release clients that received a RST_STREAM error (#1380)
Browse files Browse the repository at this point in the history
* fix: release clients that received a RST_STREAM error

* Fix test
  • Loading branch information
schmidt-sebastian committed Dec 16, 2020
1 parent 8396dac commit 0296dd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dev/src/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ export class ClientPool<T> {

return op(client)
.catch(async (err: GoogleError) => {
await this.release(requestTag, client);
if (err.message?.indexOf('RST_STREAM')) {
if (err.message?.match(/RST_STREAM/)) {
// Once a client has seen a RST_STREAM error, the GRPC channel can
// no longer be used. We mark the client as failed, which ensures that
// we open a new GRPC channel for the next request.
this.failedClients.add(client);
}
await this.release(requestTag, client);
return Promise.reject(err);
})
.then(async res => {
Expand Down
25 changes: 19 additions & 6 deletions dev/test/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ describe('Client pool', () => {
);
expect(clientPool.size).to.equal(2);

operationPromises.forEach(deferred => deferred.reject());
operationPromises.forEach(deferred => deferred.reject(new Error()));

return Promise.all(completionPromises.map(p => p.catch(() => {}))).then(
() => {
expect(clientPool.size).to.equal(0);
}
);
return Promise.all(
completionPromises.map(p => p.catch(() => {}))
).then(() => expect(clientPool.size).to.equal(0));
});

it('garbage collection calls destructor', () => {
Expand Down Expand Up @@ -283,6 +281,21 @@ describe('Client pool', () => {
expect(instanceCount).to.equal(2);
});

it('garbage collects after RST_STREAM', async () => {
const clientPool = new ClientPool<{}>(1, 1, () => {
return {};
});

const op = clientPool.run(REQUEST_TAG, () =>
Promise.reject(
new GoogleError('13 INTERNAL: Received RST_STREAM with code 2')
)
);
await op.catch(() => {});

expect(clientPool.size).to.equal(0);
});

it('keeps pool of idle clients', async () => {
const clientPool = new ClientPool<{}>(
/* concurrentOperationLimit= */ 1,
Expand Down

0 comments on commit 0296dd6

Please sign in to comment.