Skip to content

Commit

Permalink
Handle ENOENT Errors During REPL Socket Cleanup
Browse files Browse the repository at this point in the history
This PR updates the REPL socket cleanup logic to safely handle ENOENT (no such file or directory) errors when attempting to remove stale socket files. Previously, if a socket file did not exist at cleanup time, the process would crash. Now, ENOENT errors are caught and ignored, ensuring stable cleanup behavior. Any other unexpected filesystem errors will still be logged, allowing for better reliability and easier debugging of file-related issues.
  • Loading branch information
DieterReinert authored Dec 9, 2024
1 parent bfd83ca commit 5337a60
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ export const Repl = new class {
socket.end();
socket.destroy();
}).on('error', () => {
fs.unlinkSync(pathname);
try {
fs.unlinkSync(pathname);
} catch (err: any) {
// If the file doesn't exist, there's nothing to remove.
// Only log the error if it's something other than 'ENOENT'.
if (err.code !== 'ENOENT') {
console.error(`Failed to remove stale socket at ${pathname}:`, err);
}
}
});
}
}
Expand Down

0 comments on commit 5337a60

Please sign in to comment.