Skip to content

Commit e5de974

Browse files
committed
Add pool close timeout and read PORT env in CLI
1 parent 2d3c9c7 commit e5de974

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/cli/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ program
6868
.description("Start the reader daemon server")
6969
.option(
7070
"-p, --port <n>",
71-
`Port to listen on (default: ${DEFAULT_DAEMON_PORT})`,
72-
String(DEFAULT_DAEMON_PORT)
71+
`Port to listen on (env: PORT, default: ${DEFAULT_DAEMON_PORT})`,
72+
process.env.PORT ?? String(DEFAULT_DAEMON_PORT)
7373
)
7474
// The daemon now binds 1 browser per configured proxy URL, so --direct-pool-size
7575
// only controls the size of the *direct* sub-pool that's used when no proxies

src/daemon/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,11 @@ export class DaemonServer {
568568
}
569569
this.browserSessions.clear();
570570

571-
// 4. Close client and pool
572-
await this.stop();
571+
// 4. Close client and pool (with timeout to prevent hanging)
572+
await Promise.race([
573+
this.stop(),
574+
new Promise((resolve) => setTimeout(resolve, 15_000).unref()),
575+
]).catch((err) => logger.warn({ err }, "Error during pool close"));
573576

574577
logger.info("Graceful shutdown complete");
575578
}

0 commit comments

Comments
 (0)