Closed Andersama closed 1 year ago
I'm closing, took a while to try to test the pooling event loop, but that one appears to work just fine. Didn't have luck configuring cmake to get it to work, I'm not sure why it seemed like there were only two settings to change to use the polling code instead. Since I was just testing, instead I just overwrote the select source code with the polling one.
Although I'm closing this, I figured I should leave a note. There is an infinite loop bug in the select eventloop source code*. Since select eventloop works by indexing with the filedescriptor a solution might be to have a maximum number of file descriptors it can handle, with an additional fallback slot that handles or produces some error or otherwise keeps the server running smoothly. EG:
int filedescriptor = ...;
if (filedescriptor > FD_SETSIZE) {
filedescriptor = FD_SETSIZE + 1
}
fd_events[filedescriptor]; //where the additional slot is specifically reserved for handling the FD_SETSIZE error
The bug appears to be that timeout callbacks aren't set when it fails early due to the filedescriptor being too large. The result appears to be that the processing for the timeouts gets stuck in a way where all the events appear to be treated as if they have an infinite timeout. When the event loop runs it turns into an infinite cycle.
Currently the eventloop system appears to break down because it seems to use file descriptors as indexs. This is a slight problem because operating systems hand out file descriptors, they're effectively a pointer. Although file descriptors tend to be monotonically increasing compared to pointers, much like pointers, there's no guarantee for their starting or following values.
Storing data like this and indexing in this way means that the eventloop's structure
Can only handle when file descriptors are
< FD_SETSIZE
, which depending on the state of the operating system means the program may randomly crash while starting or spuriously fail when other programs open files or otherwise increase the file descriptor index.The underlying system (if this is meant to only handle a fixed number of events), should treat this structure like a fixed size array, adding new events as they're scheduled, and removing them as needed.
The structure then should look more like
The implementation then would likely need to scan linearly for the file descriptor.
Since there's no documentation I'm not sure how
select_eventloop_schedule
is supposed to function. I get the impression that a file descriptor of-1
does something special.It seems like
could be used to just store the file descriptor rather than transforming it with
+1
and-1
respectively when read. I'm also not sure what that's about.select_eventloop_run_once
might look like this:and
select_eventloop_run
might include a check against the current number of fd's being handled.Something like this should resolve #527