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

Implement non blocking cgi #362

Merged

Conversation

552020
Copy link
Collaborator

@552020 552020 commented May 16, 2024

If you want to take a look at the code, this is a first draft, it compiles, and most of the logic is there.

The only part is missing is when the CGI returns successfully (or not). We will not wait in executeCGI anymore but we will wait in startPollEventLoop: the wait in executeCGI has not been removed yet. After the CGI returned successfully in startPollEventLoop, where we wait for all processes (-1) without blocking (WNOHANG), we go back to poll, the event we listen for for that connection will be POLLOUT. And then we need a flag like CGIhasFinished. We already collect the exitStatus of the CGI which is set in the Connection object.

The code to read the buffer written by the CGI is in handleConnection > buildResponse > routeRequest > handleRequest > executeCGI. We should re-enter handleConnection and buildResponse, but skip the whole logic we already executed the first time we entered it to execute the CGI. Alternatively we could also pass the fd of the pipe when we execute _connection.addCGI(pid); but this is dirtier.

I don't know if you @lmangall has capacity to think about it. I guess with a flag like _CGIhasTerminated (which means it has been executed or kill) we could skip all the unnecessary part of the code, and come to the point where we check the status and read from the buffer. Probably the first step should be just split executeCGI in two function: executeCGI and processExecutedCGI (or something like this), where we read from the buffer or depending on the status code we send back some error.

@552020 552020 self-assigned this May 16, 2024
@552020 552020 changed the title Iimplement non blocking cgi Implement non blocking cgi May 16, 2024
@552020 552020 marked this pull request as draft May 16, 2024 09:56
@552020 552020 requested review from dantol29 and lmangall May 16, 2024 10:50
@dantol29
Copy link
Owner

@552020 It does not compile according to GitHub actions Ubuntu

@552020
Copy link
Collaborator Author

552020 commented May 16, 2024

@552020 It does not compile according to GitHub actions Ubuntu

@dantol29 thanks for checking: fixed.

@lmangall
Copy link
Collaborator

@552020 Just to know where we stand : Is this code an enhanced version of of this branch ?
#345

@552020
Copy link
Collaborator Author

552020 commented May 16, 2024

@552020 Just to know where we stand : Is this code an enhanced version of of this branch ? #345

It's from scratch.

552020 added 5 commits May 16, 2024 15:52
…GI don't wait and read the CGI output but pass the fd of the pipe to the resoponse object
…m-multiple-sockets

tests(Dockerfile): upload Dockerfile for multi socket and upload Dock…
@dantol29
Copy link
Owner

@lmangall Stefano and I made it work!! Now we have proper CGI timeout and it is non-blocking!

@552020 552020 requested a review from dantol29 May 20, 2024 18:48
@552020 552020 marked this pull request as ready for review May 20, 2024 18:50
@552020
Copy link
Collaborator Author

552020 commented May 21, 2024

This needs to be accepted yet. @lmangall @dantol29

Copy link
Owner

@dantol29 dantol29 left a comment

Choose a reason for hiding this comment

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

LGTM! Did you test after I left?

@552020
Copy link
Collaborator Author

552020 commented May 21, 2024

LGTM! Did you test after I left?

We were testing in the main therefore it was failing. But I didn't test the branch, soon to be main.

@552020 552020 merged commit 6ec0939 into dantol29:main May 21, 2024
1 check passed
@552020 552020 deleted the slombard/webf-15-implement-non-blocking-cgi branch May 21, 2024 06:05
@lmangall
Copy link
Collaborator

Nice, great job !

@lmangall
Copy link
Collaborator

Did you test with the "parallel CGI" test ?

@552020
Copy link
Collaborator Author

552020 commented May 21, 2024

Did you test with the "parallel CGI" test ?

I tried but we have some issues: https://linear.app/web-serv/issue/WEB-330/cgi-bug-in-main-%F0%9F%9A%A8

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