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.
This commit is contained in:
parent
ddc3567449
commit
6d066831eb
2 changed files with 22 additions and 1 deletions
|
|
@ -47,9 +47,12 @@ export class HttpServer {
|
||||||
private app: FastifyInstance | null = null;
|
private app: FastifyInstance | null = null;
|
||||||
private port: number = 3456;
|
private port: number = 3456;
|
||||||
private running: boolean = false;
|
private running: boolean = false;
|
||||||
|
private startingPromise: Promise<number> | null = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the HTTP server.
|
* 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 services - Service instances to pass to route handlers
|
||||||
* @param sshModeSwitchCallback - Callback for SSH mode switching
|
* @param sshModeSwitchCallback - Callback for SSH mode switching
|
||||||
* @param preferredPort - Port to try first (default 3456)
|
* @param preferredPort - Port to try first (default 3456)
|
||||||
|
|
@ -60,6 +63,24 @@ export class HttpServer {
|
||||||
sshModeSwitchCallback: (mode: 'local' | 'ssh') => Promise<void>,
|
sshModeSwitchCallback: (mode: 'local' | 'ssh') => Promise<void>,
|
||||||
preferredPort: number = 3456,
|
preferredPort: number = 3456,
|
||||||
host: string = '127.0.0.1'
|
host: string = '127.0.0.1'
|
||||||
|
): Promise<number> {
|
||||||
|
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<void>,
|
||||||
|
preferredPort: number,
|
||||||
|
host: string
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
this.app = Fastify({ logger: false });
|
this.app = Fastify({ logger: false });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ export const ActivityTimeline = React.memo(function ActivityTimeline({
|
||||||
|
|
||||||
if (messages.length === 0) {
|
if (messages.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div className="rounded-md border border-[var(--color-border)] p-3 text-xs text-[var(--color-text-muted)]">
|
<div className="rounded-md border border-[var(--color-border)] p-3 pl-5 text-xs text-[var(--color-text-muted)]">
|
||||||
<p>No messages</p>
|
<p>No messages</p>
|
||||||
<p className="mt-1 text-[11px]">Send a message to a member to see activity.</p>
|
<p className="mt-1 text-[11px]">Send a message to a member to see activity.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue