From 760239fa60e7d45c47e2ecdf14f1898e07daf785 Mon Sep 17 00:00:00 2001 From: Daniil Gaponov Date: Fri, 3 Apr 2026 12:33:56 +0300 Subject: [PATCH] fix(dev): clean up stale IPC socket and abort on client dev server failure --- src/commands/dev/client.ts | 16 +++++++++++----- src/commands/dev/index.ts | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/commands/dev/client.ts b/src/commands/dev/client.ts index 0b81832..6590cac 100644 --- a/src/commands/dev/client.ts +++ b/src/commands/dev/client.ts @@ -165,6 +165,16 @@ async function buildDevServer(config: NormalizedServiceConfig) { options.ipc = path.resolve(getAppRunPath(config), 'client.sock'); } + // Remove stale socket file from a previous process to avoid EADDRINUSE error + // when restarting the dev server while the old process is still running. + if (options.ipc && typeof options.ipc === 'string') { + try { + fs.unlinkSync(options.ipc); + } catch { + // ignore if file doesn't exist + } + } + const proxy = options.proxy || []; if (config.client.lazyCompilation && bundler !== 'rspack') { proxy.push({ @@ -212,11 +222,7 @@ async function buildDevServer(config: NormalizedServiceConfig) { ); } - try { - await server.start(); - } catch (e) { - logger.logError(`Cannot start ${bundler} dev server`, e); - } + await server.start(); if (options.ipc && typeof options.ipc === 'string') { fs.chmod(options.ipc, 0o666, (e) => logger.logError('', e)); diff --git a/src/commands/dev/index.ts b/src/commands/dev/index.ts index 4b7db7a..e35358d 100755 --- a/src/commands/dev/index.ts +++ b/src/commands/dev/index.ts @@ -83,11 +83,17 @@ export default async function (config: NormalizedServiceConfig) { let clientCompilation: WebpackDevServer | RspackDevServer | undefined; if (shouldCompileClient) { const {watchClientCompilation} = await import('./client.js'); - clientCompilation = await watchClientCompilation(config, () => { - logger.success('Manifest was compiled successfully'); - clientCompiled = true; - startNodemon(); - }); + try { + clientCompilation = await watchClientCompilation(config, () => { + logger.success('Manifest was compiled successfully'); + clientCompiled = true; + startNodemon(); + }); + } catch (e) { + logger.logError('Failed to start client dev server', e); + await serverCompilation?.stop('SIGTERM'); + process.exit(1); + } } process.on('SIGINT', async () => {