Skip to content

Commit

Permalink
fix: remove the pipe file before starting the ipc server (#459)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
  • Loading branch information
louislam and privatenumber committed Feb 10, 2024
1 parent e23592e commit 0ed0097
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/utils/ipc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ export const createIpcServer = async () => {
const pipePath = getPipePath(process.pid);
await fs.promises.mkdir(tmpdir, { recursive: true });

/**
* Fix #457 (https://github.com/privatenumber/tsx/issues/457)
*
* Avoid the error "EADDRINUSE: address already in use"
*
* If the pipe file already exists, it means that the previous process has been closed abnormally.
*
* We can safely delete the pipe file, the previous process must has been closed,
* as pid is unique at the same.
*/
await fs.promises.rm(pipePath, {
force: true,
});

await new Promise<void>((resolve, reject) => {
server.listen(pipePath, resolve);
server.on('error', reject);
Expand Down

0 comments on commit 0ed0097

Please sign in to comment.