Skip to content

reset listening state for each secondary server#4802

Closed
cjihrig wants to merge 3 commits intofastify:ci/node-20from
cjihrig:fix
Closed

reset listening state for each secondary server#4802
cjihrig wants to merge 3 commits intofastify:ci/node-20from
cjihrig:fix

Conversation

@cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Jun 8, 2023

The listenCallback() function is called for each secondary address that a server should listen on. However, each call sets the listening state to true, so subsequent addresses fail with FST_ERR_REOPENED_SERVER. This commit resets the state on each call.

Note:
I had a bit of trouble creating a test for this. The existing tests all have plan() calls expecting the number of listening addresses to match the number of addresses on the system. This is an incorrect assumption. The listening logic in multipleBindings() in lib/server.js ignores errors encountered when trying to listen. For example, on my machine, I have 3 interfaces, but Fastify can only listen on two of them.

Checklist

The listenCallback() function is called for each secondary
address that a server should listen on. However, each call sets
the listening state to true, so subsequent addresses fail with
FST_ERR_REOPENED_SERVER. This commit resets the state on each
call.
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 8, 2023

ping @mcollina

Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should L107 be removed? and move the comment to new place?

@metcoder95
Copy link
Member

The listenCallback is the one that turns on the switch as soon as the returned callback is called. As is reused across the multipleBindings I believe it is what's causing the issues.

Maybe we can isolate the listenCallback and make a new function that just handles the new instances and waits until all of them are listening (or failed, does not matter), before calling marking the server as already listening.

function listenCallback (server, listenOptions) {

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 9, 2023

The listenCallback is the one that turns on the switch as soon as the returned callback is called. As is reused across the multipleBindings I believe it is what's causing the issues.

Yes, that's what I was saying in the OP. If you want to take this over and implement your suggestion, I'm fine with that.

@mcollina mcollina deleted the branch fastify:ci/node-20 June 9, 2023 12:53
@mcollina mcollina closed this Jun 9, 2023
@cjihrig cjihrig deleted the fix branch June 9, 2023 13:52
@cjihrig
Copy link
Contributor Author

cjihrig commented Jun 9, 2023

I've moved this to #4810 since the node-20 branch was merged.

Should L107 be removed? and move the comment to new place?

I'm not sure about that because it's possible that the if statement on line 122 will not be entered, depending on the user's machine setup.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants