-
-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix startup race condition #3367
Conversation
It looks like you also need to await here |
PR tested on multiple instances, seems OK
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I'd like to see one more change. Now that bind is async, I think we should be using fs/promises
instead of sync calls:
diff --git a/endpoint.js b/endpoint.js
index 8154aef1..8f8e959a 100644
--- a/endpoint.js
+++ b/endpoint.js
@@ -1,7 +1,7 @@
'use strict';
// Socket address parser/formatter and server binding helper
-const fs = require('node:fs');
+const fs = require('node:fs/promises');
const sockaddr = require('sockaddr');
module.exports = function endpoint (addr, defaultPort) {
Since fs.exists
has been deprecated for years, switch it to use fs.access
or fs.stat
before the await fs.unlink(path);
or ignore errors when the file doesn't exist: await fs.rm(this.path, { force: true }); |
endpoint.js
Outdated
opts.host = this.host; | ||
opts.port = this.port; | ||
} | ||
server.listen(opts, done); | ||
|
||
return await new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return await new Promise((resolve, reject) => { | |
return new Promise((resolve, reject) => { |
There's no need to await here.
When I "grep node:fs" I didn't find many "promises" so I assumed it would be better not to change. I chose "rm" for simplicity... |
Thanks! Great job on the diagnosis and the fix. |
Fixes #3366
Changes proposed in this pull request:
Checklist: