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: refactor fast timers, fix UND_ERR_CONNECT_TIMEOUT on event loop blocking #3495

Merged
merged 8 commits into from
Aug 27, 2024

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Aug 23, 2024

superseeds #3494
superseeds #3418
fixes #3493
fixes #3410

  • an internal "clock" is now used instead of Date.now() - ensuring that changes of the system clock wont effect the timers
  • timers.js exports a now method to retrieve the value of the internal clock
  • fasttimers clearTimeout expects a FastTimer instance or a native Timer. Before it accepted also undefined or null values
  • connect timeouts are now using fasttimers

Based on the work of @ronag i refactored the fast timers and hopefully fixed also the connection timeout bug when the event loop is blocked.

@Uzlopak Uzlopak marked this pull request as ready for review August 23, 2024 16:38
@Uzlopak Uzlopak changed the title chore: refactor fast timers fix: refactor fast timers Aug 23, 2024
@Uzlopak Uzlopak changed the title fix: refactor fast timers fix: refactor fast timers, fix UND_ERR_CONNECT_TIMEOUT on event loop blocking Aug 23, 2024
Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

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

This is a huge PR... not sure I have time to review properly in forseeable future.

@thisislvca
Copy link

This is a big issue over at Vercel, know it's a big PR but it's also quite important for lots of people :)

@ronag
Copy link
Member

ronag commented Aug 24, 2024

There are simpler PRs that solve the issue. I think the problem here is that we are combining a significant refactoring with bug fixes.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

can you run the benchmark before/after to see if this impacted us at all?

@mcollina
Copy link
Member

After a quick skim it seems fine, and all tests are passing. If it introduces some regresisons, then I'm pretty sure some users of Next.js/Vercel would report this quickly find out.

@ronag
Copy link
Member

ronag commented Aug 24, 2024

I'm +-0

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 24, 2024

I want to add a small explaination of this refactoring.

I wanted to modify the fasttimer implementation. Yes it is kind of simple while you are implementing it and everything makes sense. But when working on it the first time, it is kind of hard to grok. So I started to comment the code and e.g. also replace the magic numbers with constants, and renamed the atrtibutes to be more expressive.

While I was investigating how the native timers are structured, I realized I should use their data structure/naming of the attributes. Thats why I renamed e.g. delay with _idleTimeout or callback with _onTimeout.

image

Also I tried to rename variables. when a different name was making more sense. E.g. in client-h1.js value to delay.

So in my opinion to review the timers.js file the first step is to just read the comments and check if it matches with the code it describes. And if it is good commented you should have a good idea on how the fast timers actually work.

The rest should be then easy to review.

@ronag
Copy link
Member

ronag commented Aug 24, 2024

IMHO all the comments and explanations make it harder to grasp and read. But if everyone else is happy with it I won't block. Good job.

@ronag
Copy link
Member

ronag commented Aug 24, 2024

Could you maybe summarize what behavior changes this introduces?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 24, 2024

Of course. I will in about 30 min, when i am back from groceries shopping ;)

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 24, 2024

Well, I was looking into the code while writing what changes I implemented. I made a coverage check and realized, that the changes in client-h1.js seem to be not covered by a unit test. So I am currently implementing a unit test for that, just as a sanity check.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 24, 2024

I reverted the changes regarding timeoutDeadline in client-h1,js as those changes are not covered by a unit test. As soon as I find a test case and those lines fix the test then I would add them back.

@thisislvca
Copy link

Is there a chance to push out the Vercel-related errror fix first (so the most urgent) and then open a separate PR for everything else?

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

lgtm

@Uzlopak Uzlopak merged commit 8a09d77 into nodejs:main Aug 27, 2024
32 checks passed
@Uzlopak Uzlopak deleted the refactor-fast-timers branch August 27, 2024 15:07
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