Skip to content
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: allow event loop to process during wait queue processing #2537

Merged
merged 4 commits into from Sep 9, 2020

Conversation

mbroadst
Copy link
Member

@mbroadst mbroadst commented Sep 8, 2020

Running processWaitQueue on the next tick allows the event loop to process while the connection pool is processing large numbers of wait queue members.

NODE-2803

Running `processWaitQueue` on the next tick allows the event loop
to process while the connection pool is processing large numbers of
wait queue members.

NODE-2803
Copy link
Contributor

@emadum emadum left a comment

Choose a reason for hiding this comment

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

LGTM, but it looks like this made a test start failing in CI (unless that's unrelated)

@mbroadst mbroadst force-pushed the NODE-2803/process-wait-queue-nextTick branch from 0c92d66 to 71038b7 Compare September 9, 2020 14:01
`endSession` must wait for all the machinery behind the scenes to
check out a connection and write a message before considering its
job finished.
@mbroadst mbroadst force-pushed the NODE-2803/process-wait-queue-nextTick branch from 71038b7 to e340b8f Compare September 9, 2020 14:16
Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

LGTM

@mbroadst mbroadst merged commit 4e03dfa into 3.6 Sep 9, 2020
@mbroadst mbroadst deleted the NODE-2803/process-wait-queue-nextTick branch September 9, 2020 21:19
@vkarpov15
Copy link
Contributor

Unfortunately this is a breaking change for anyone that uses Sinon's useFakeTimers() for testing, see Automattic/mongoose#9417. Mongoose strongly advises against using timer mocks, but people use them anyway, so I think it's worth thinking about: do we need to use setImmediate() here, or can we get away with using process.nextTick(), which sinon doesn't stub?

@mbroadst
Copy link
Member Author

@vkarpov15 hmm, the original implementation used process.nextTick but after discussion around the guidance in this document (specifically "We recommend developers use setImmediate() in all cases because it's easier to reason about.") we opted to use setImmediate.

There's a possibility when using process.nextTick that we will still be too greedy and won't ever allow the event loop to process critical events. I think your guidance to those users is correct, they should not be mocking timers outside of unit tests. Perhaps your page on using mock timers could be updated to use the workarounds you provided them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants