Skip to content

Commit

Permalink
test(plugin-consortium-manual): fix port binding - multiple API servers
Browse files Browse the repository at this point in the history
1. The ConnectRPC port defaults to 6000 in the API server so for test cases where multiple
instances of the API server are created and started, we need to specify the ports
explicitly in the API server config so that they don't clash with each other casusing the
test to fail.
2. The fix here was to simply bind to port 0 for all the ConnectRPC listeners which
eliminated the possibility of a clash and the test is passing once again.
3. I also snuck in a quality of life improvement for contributors: the API server will no
longer log the entire details of the fastify server that is being used for CRPC thereby
reducing the verbosity of the logs by a wide margin.

Crash logs that revealed the bug in the test case:

```sh
024-05-31T20:14:00.9554919Z [2024-05-31T20:14:00.953Z] ERROR (api-server):
Failed to start ApiServer Error: listen EADDRINUSE: address already in use 127.0.0.1:6000
2024-05-31T20:14:00.95Z     at Http2Server.setupListenHandle [as _listen2] (node:net:1817:16)
2024-05-31T20:14:00.95Z     at listenInCluster (node:net:1865:12)
2024-05-31T20:14:00.95Z     at doListen (node:net:2014:7)
2024-05-31T20:14:00.95Z     at processTicksAndRejections (node:internal/process/task_queues:83:21)
2024-05-31T20:14:00.95Z     at runNextTicks (node:internal/process/task_queues:64:3)
2024-05-31T20:14:00.95Z     at processImmediate (node:internal/timers:447:9) {
2024-05-31T20:14:00.95Z   code: 'EADDRINUSE',
2024-05-31T20:14:00.95Z   errno: -98,
2024-05-31T20:14:00.95Z   syscall: 'listen',
2024-05-31T20:14:00.95Z   address: '127.0.0.1',
2024-05-31T20:14:00.95Z   port: 6000
2024-05-31T20:14:00.95Z }
```

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Jun 6, 2024
1 parent b98fa01 commit 40f7fd8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,13 @@ export class ApiServer {

log.debug("%s Registering %o CRPC routes handler(s).", fn, svcCount);

const registration = await this.crpcServer.register(fastifyConnectPlugin, {
await this.crpcServer.register(fastifyConnectPlugin, {
routes: crpcRoutesHandler,
shutdownTimeoutMs: 5000,
grpc: true,
grpcWeb: true,
});
log.debug("%s Fastify registration OK=%o", fn, registration);
log.debug("%s Fastify CRPC service registration OK", fn);

const crpcUrl = await this.crpcServer.listen({
host: crpcHost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ describe(testCase, () => {
apiServerOptions.cockpitPort = 0;
apiServerOptions.grpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.crpcPort = 0;
const config =
await configService.newExampleConfigConvict(apiServerOptions);

Expand Down Expand Up @@ -250,6 +251,7 @@ describe(testCase, () => {
apiServerOptions.grpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.plugins = [];
apiServerOptions.crpcPort = 0;
const config =
await configService.newExampleConfigConvict(apiServerOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ describe(testCase, () => {
apiServerOptions.cockpitPort = 0;
apiServerOptions.grpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.crpcPort = 0;
const config =
await configService.newExampleConfigConvict(apiServerOptions);

Expand Down Expand Up @@ -266,6 +267,7 @@ describe(testCase, () => {
apiServerOptions.grpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.plugins = [];
apiServerOptions.crpcPort = 0;
const config =
await configService.newExampleConfigConvict(apiServerOptions);

Expand Down Expand Up @@ -317,6 +319,7 @@ describe(testCase, () => {
apiServerOptions.grpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.plugins = [];
apiServerOptions.crpcPort = 0;
const config =
await configService.newExampleConfigConvict(apiServerOptions);
pluginRegistry.add(pluginConsortiumManual);
Expand Down

0 comments on commit 40f7fd8

Please sign in to comment.