fix: come back quickly after a hub restart, and pin the dependencies
Two things helloeco ran into while wiring the gateway. grpc-js waits a second before its second reconnect attempt and backs off towards two minutes. That is right for a far-away service and wrong for a hub on the same network: after a restart or a deploy a gateway sits out the backoff with requests in hand. The client now sets initial 200 ms and a 5 s ceiling, and a caller's own channelOptions still win. The client exposes the options it ended up with, which is the only way to tell a default that applies from one that was silently replaced. The dependencies are pinned exactly instead of by range. This package is consumed by a handful of services, not by a library ecosystem, and a surprise minor of grpc-js is what breaks a portal at three in the morning. Raising one is a commit, with the skew job in front of it. Guards: the defaults and the precedence are asserted (probed by mutation), plus a case that a run works again once the hub is back. Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
parent
986377f1df
commit
2131193f1f
4 changed files with 86 additions and 6 deletions
|
|
@ -275,3 +275,43 @@ async function waitFor<T>(produce: () => Promise<T | undefined>, timeoutMs = 3_0
|
|||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
}
|
||||
}
|
||||
|
||||
describe('the channel after a hub comes back', () => {
|
||||
it('is built to retry soon, not after a second', () => {
|
||||
// grpc-js waits a second before its second reconnect attempt and
|
||||
// backs off towards two minutes. That is right for a far-away
|
||||
// service and wrong for a hub on the same network: after a
|
||||
// restart or a deploy, a gateway would sit out the backoff with
|
||||
// requests in hand.
|
||||
const client = new ChainClient({ address: '127.0.0.1:1' });
|
||||
assert.equal(client.channelOptions['grpc.initial_reconnect_backoff_ms'], 200);
|
||||
assert.equal(client.channelOptions['grpc.max_reconnect_backoff_ms'], 5_000);
|
||||
client.close();
|
||||
});
|
||||
|
||||
it('lets a caller override what the client set', () => {
|
||||
const client = new ChainClient({
|
||||
address: '127.0.0.1:1',
|
||||
channelOptions: { 'grpc.initial_reconnect_backoff_ms': 1_234 },
|
||||
});
|
||||
assert.equal(client.channelOptions['grpc.initial_reconnect_backoff_ms'], 1_234);
|
||||
// And the other default is still there.
|
||||
assert.equal(client.channelOptions['grpc.max_reconnect_backoff_ms'], 5_000);
|
||||
client.close();
|
||||
});
|
||||
|
||||
it('works again once the hub is back', async () => {
|
||||
const hub = new FakeHub();
|
||||
const address = await hub.start();
|
||||
const client = new ChainClient({ address, deadlineMs: 5_000 });
|
||||
await client.health();
|
||||
|
||||
await hub.restart();
|
||||
hub.succeeds({ report: 'wieder da' });
|
||||
const result = await client.submit({ flowYaml: FLOW });
|
||||
assert.equal(asText(result.outputs.report), 'wieder da');
|
||||
|
||||
client.close();
|
||||
await hub.close();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue