diff --git a/yarn-project/blob-sink/package.json b/yarn-project/blob-sink/package.json index f57da57e35a9..daa2c07ca27a 100644 --- a/yarn-project/blob-sink/package.json +++ b/yarn-project/blob-sink/package.json @@ -67,7 +67,6 @@ "@types/node": "^18.7.23", "@types/source-map-support": "^0.5.10", "@types/supertest": "^6.0.2", - "get-port": "^7.1.0", "jest": "^29.5.0", "jest-mock-extended": "^3.0.3", "supertest": "^7.0.0", diff --git a/yarn-project/blob-sink/src/client/http.test.ts b/yarn-project/blob-sink/src/client/http.test.ts index 60486c8a21bc..046fb0811d0c 100644 --- a/yarn-project/blob-sink/src/client/http.test.ts +++ b/yarn-project/blob-sink/src/client/http.test.ts @@ -1,17 +1,14 @@ import { Blob } from '@aztec/foundation/blob'; import { Fr } from '@aztec/foundation/fields'; -import getPort from 'get-port'; - import { BlobSinkServer } from '../server/server.js'; import { runBlobSinkClientTests } from './blob-sink-client-tests.js'; import { HttpBlobSinkClient } from './http.js'; describe('HttpBlobSinkClient', () => { runBlobSinkClientTests(async () => { - const port = await getPort(); const server = new BlobSinkServer({ - port, + port: 0, }); await server.start(); diff --git a/yarn-project/blob-sink/src/server/server.ts b/yarn-project/blob-sink/src/server/server.ts index 030f58d147ad..9474aa3f63fe 100644 --- a/yarn-project/blob-sink/src/server/server.ts +++ b/yarn-project/blob-sink/src/server/server.ts @@ -6,6 +6,7 @@ import { NoopTelemetryClient } from '@aztec/telemetry-client/noop'; import express, { type Express, type Request, type Response, json } from 'express'; import { type Server } from 'http'; +import { AddressInfo } from 'net'; import { z } from 'zod'; import { type BlobStore, DiskBlobStore } from '../blobstore/index.js'; @@ -23,7 +24,7 @@ import { BlobSinkMetrics } from './metrics.js'; * await service.stop(); */ export class BlobSinkServer { - public readonly port: number; + public port: number; private app: Express; private server: Server | null = null; @@ -135,8 +136,17 @@ export class BlobSinkServer { } public start(): Promise { - return new Promise(resolve => { + return new Promise((resolve, reject) => { this.server = this.app.listen(this.port, () => { + // Extract port from server address, allows setting address when + // server is started with port 0 + const address = this.server?.address() as AddressInfo | null; + if (!address) { + this.log.error('Server address not found'); + this.stop().then(() => reject(new Error('Server address not found'))); + } + + this.port = address!.port; this.log.info(`Server is running on http://localhost:${this.port}`); resolve(); }); diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index dca6e05178e3..f73b616c3383 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -352,7 +352,6 @@ __metadata: "@types/source-map-support": "npm:^0.5.10" "@types/supertest": "npm:^6.0.2" express: "npm:^4.21.1" - get-port: "npm:^7.1.0" jest: "npm:^29.5.0" jest-mock-extended: "npm:^3.0.3" source-map-support: "npm:^0.5.21"