From 6d066831ebb8fd33bad7a3c1f4926fc07cb0d158 Mon Sep 17 00:00:00 2001 From: iliya Date: Fri, 20 Mar 2026 16:19:51 +0200 Subject: [PATCH] feat: implement deduplication for concurrent server start calls - Enhanced the HttpServer class to prevent multiple concurrent calls to the start() method by introducing a startingPromise that ensures subsequent calls await the same promise. - Added a private doStart method to encapsulate the server startup logic. - Updated documentation to reflect the new behavior of the start method. - Adjusted the ActivityTimeline component to improve padding in the "No messages" state for better visual alignment. --- .../services/infrastructure/HttpServer.ts | 21 +++++++++++++++++++ .../team/activity/ActivityTimeline.tsx | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/services/infrastructure/HttpServer.ts b/src/main/services/infrastructure/HttpServer.ts index f4469432..81ad929d 100644 --- a/src/main/services/infrastructure/HttpServer.ts +++ b/src/main/services/infrastructure/HttpServer.ts @@ -47,9 +47,12 @@ export class HttpServer { private app: FastifyInstance | null = null; private port: number = 3456; private running: boolean = false; + private startingPromise: Promise | null = null; /** * Start the HTTP server. + * Deduplicates concurrent calls — if start() is already in progress, + * subsequent calls await the same promise. * @param services - Service instances to pass to route handlers * @param sshModeSwitchCallback - Callback for SSH mode switching * @param preferredPort - Port to try first (default 3456) @@ -60,6 +63,24 @@ export class HttpServer { sshModeSwitchCallback: (mode: 'local' | 'ssh') => Promise, preferredPort: number = 3456, host: string = '127.0.0.1' + ): Promise { + if (this.startingPromise) { + return this.startingPromise; + } + + this.startingPromise = this.doStart(services, sshModeSwitchCallback, preferredPort, host); + try { + return await this.startingPromise; + } finally { + this.startingPromise = null; + } + } + + private async doStart( + services: HttpServices, + sshModeSwitchCallback: (mode: 'local' | 'ssh') => Promise, + preferredPort: number, + host: string ): Promise { this.app = Fastify({ logger: false }); diff --git a/src/renderer/components/team/activity/ActivityTimeline.tsx b/src/renderer/components/team/activity/ActivityTimeline.tsx index 449a8dcd..31b5510b 100644 --- a/src/renderer/components/team/activity/ActivityTimeline.tsx +++ b/src/renderer/components/team/activity/ActivityTimeline.tsx @@ -477,7 +477,7 @@ export const ActivityTimeline = React.memo(function ActivityTimeline({ if (messages.length === 0) { return ( -
+

No messages

Send a message to a member to see activity.