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

Handle eintr in kqueue/epoll better related to timers #15875

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

@robobun
Copy link

robobun commented Dec 19, 2024

Updated 2:32 AM PT - Dec 19th, 2024

@Jarred-Sumner, your commit cd2249d has passed in #8221! 🎉


🧪   try this PR locally:

bunx bun-pr 15875

@@ -129,6 +129,14 @@ pub const All = struct {
return VirtualMachine.get().timer.last_id;
}

pub export fn Bun__updateTimeoutAfterEINTR(this: *VirtualMachine, timeout: *timespec) i32 {
Copy link

Choose a reason for hiding this comment

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

Since you use this function thrice in the same repeating pattern I suggest wrapping that repeating logic inside e.g.

pub export fn Bun__updateTimeoutAfterEINTR(this: *VirtualMachine, timeout: **timespec) bool {
    if (timeout_update_ctx && timeout && timeout.* && !this.timer.getTimeout(timeout.*)) {
        timeout.* = NULL;
    }
    return !(timeout_update_ctx && timeout && timeout.* && timeout.*->tv_sec == 0 && timeout.*->tv_nsec == 0);
}

This would simplify callsites e.g.

        if (UNLIKELY(rc == -1 && errno == EINTR)) {
            if (Bun__updateTimeoutAfterEINTR(timeout_update_ctx, timeout)) {
                continue;
            }
            loop->num_ready_polls = 0;
            break;
        }

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

Successfully merging this pull request may close these issues.

3 participants