libxev icon indicating copy to clipboard operation
libxev copied to clipboard

Fix overflow in `kqueue` backend

Open Corendos opened this issue 1 year ago • 1 comments

Closes #111

@mitchellh I managed to write a test to avoid regressions but I'm not sure it's deterministic, should I still add it?

Corendos avatar Sep 10 '24 09:09 Corendos

While discussing with @steeve and re-reading the issue, I think it's better to add more context. There are basically two ways we can solve that.

1. Cap the amount of completion executed per tick

This is simply breaking from the loop as I did in this PR.

One issue with that is that, if we are in loop.run(.once), we will potentially "miss" completions because we are capped to 256 completions in one tick. We will thus give back control to the user and the remaining completions will be handled in the next tick.

2. Drain all the completions in one tick

For that, we need to add another loop around the while (self.completions.pop()) |c| { ... } block, so that we handle all the completions that are ready.

One issue with this solution is that it can end up needing multiple call to kevent_syscall and it kind of feels weird with respect to the .once


So, in the end, that's why I went for the first solution, but I can get that it's not what you would expect @mitchellh. Let me know what you feel is best, and I'll make it work 😁

Corendos avatar Sep 10 '24 13:09 Corendos

Gentle ping @mitchellh

steeve avatar Nov 19 '24 15:11 steeve

Apologies, I just got our tests passing again. Let me take a look at this now :)

mitchellh avatar Nov 19 '24 18:11 mitchellh

Alright, this looks good, at least to start. I think the caveat that once may not complete everything is reasonable.

mitchellh avatar Nov 19 '24 18:11 mitchellh