fix race condition in linuxWaitFd

This commit is contained in:
Bill Nagel 2021-01-11 22:21:18 -05:00 committed by Veikka Tuominen
parent 1bd434fd18
commit cc5e5cca83

View File

@ -440,13 +440,11 @@ pub const Loop = struct {
.overlapped = ResumeNode.overlapped_init,
},
};
var need_to_delete = false;
var need_to_delete = true;
defer if (need_to_delete) self.linuxRemoveFd(fd);
suspend {
if (self.linuxAddFd(fd, &resume_node.base, flags)) |_| {
need_to_delete = true;
} else |err| switch (err) {
self.linuxAddFd(fd, &resume_node.base, flags) catch |err| switch (err) {
error.FileDescriptorNotRegistered => unreachable,
error.OperationCausesCircularLoop => unreachable,
error.FileDescriptorIncompatibleWithEpoll => unreachable,
@ -456,6 +454,7 @@ pub const Loop = struct {
error.UserResourceLimitReached,
error.Unexpected,
=> {
need_to_delete = false;
// Fall back to a blocking poll(). Ideally this codepath is never hit, since
// epoll should be just fine. But this is better than incorrect behavior.
var poll_flags: i16 = 0;
@ -479,7 +478,7 @@ pub const Loop = struct {
};
resume @frame();
},
}
};
}
}