jetforce icon indicating copy to clipboard operation
jetforce copied to clipboard

Serving requests stops when JetForce is executing CGI program?

Open acidus99 opened this issue 10 months ago • 3 comments

I noticed a odd behavior: Jetforce seems to block processing any other incoming requests while a CGI bin program is running.

Here is a simple CGI program that waits for the number of seconds passed in via the query string, before sending a response line and simple body:

gemini://gemi.dev/cgi-bin/wait.py?10

While that CGI bin program is running, other requests to the same capsule where Jetforce is running seem to block and not get any content. As soon as the CGI program ends, then the other requests are serviced and content is returned. It's as if, while running CGI script, Jetforce is unable to handle any other requests.

Here is a screen capture showing the problem. I have 2 windows of Lagrange side-by-side. I can successfully navigate around my capsule on the left side. As soon as I send a request for the CGI program, telling it to wait for 10 seconds:

Image

acidus99 avatar Feb 22 '25 21:02 acidus99

Hey!

The expected behavior is that the server will block until the status line is received from the CGI script, and then it will unblock and allow the rest of the body to be streamed. Code is here:

https://github.com/michael-lazar/jetforce/blob/master/jetforce/app/static.py#L174-L234

I admit this is not ideal, but the router API was written based around returning a Response class which requires the status & meta upfront to build a response. I'm sure it would be possible to come up with a solution, maybe adding support for a new AsyncResponse class or something like that, but it would require some care.

https://github.com/michael-lazar/jetforce/blob/master/jetforce/app/base.py#L98

michael-lazar avatar Feb 24 '25 00:02 michael-lazar

So the faster the CGI returns a status line, the faster it will unblock?

Right now much of Gemipedia's code does something like:

make network request //this could take a while
if error, return gemini error status line
else return 20 response + body

But sounds like it would be faster if I instead of:

write 20 status line
make network request //this could take a while
if error, write text of error into body
else write reset of body

acidus99 avatar Mar 01 '25 18:03 acidus99

Yes I believe that's true

michael-lazar avatar Mar 02 '25 00:03 michael-lazar