-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
asynchttpserver "Bad file descriptor" crashes #12526
Comments
I did some investigation and it may be an issue with Jester, but I'm not sure. nginx config: http {
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
proxy_pass http://localhost:5000/;
}
}
} Server: import jester
routes:
get "/":
resp Http200 Run: sudo nginx # -s reload if already running
nim c -d:useStdLib -r server.nim
curl http://localhost This immediately results in the bad file descriptor exception, so I did some digging, and it appears to happen because the socket is closed before the response gets sent, due to Jester calling Likewise, if we replace the server code with the following, where import asynchttpserver, asyncdispatch
var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} =
asyncCheck req.respond(Http200, "Hello World")
waitFor server.serve(Port(5000), cb) Jester's |
So there is at least two issues here:
|
I don't want to leave my server loop to handle an exception, as that is disruptive to all other clients and whatever state I'm working with in the server loop. Hence #12325. |
To mitigate this so I can use Jester with asynchttpserver, I've hacked together a fork that removes support for httpbeast and awaits the requests properly. There might be a way to keep httpbeast support and await asynchttpserver's requests, but this works for now. |
There certainly is a way to keep httpbeast: httpbeast is enabled statically so there is absolutely no reason you would need to remove httpbeast support for this. I'm curious what the actual fix is and would like to merge it into Jester. |
It's not so much supporting httpbeast, it's the critical path (the Oh also, the leak/race condition I mentioned on IRC went away when I switched to asynchttpserver. Unfortunately I don't have an easy way to reproduce it apart from running httpbeast on nitter.net with its large amount of traffic that makes it easier to trigger. A more analytical approach might be better, it seems to be a file descriptor leak but that's just a guess |
If the repository Zed created doesn't help, and #12325 doesn't help, and Zed's |
Turns out supporting both with async was very easy, opened dom96/jester#236 |
asynchttpserver crashes due to cancelled(?) requests:
There's a few ways to trigger this. My use case is a website, where navigating around quickly can cause cancelled requests which triggers the error. Another way is scrubbing around a video stream to parts not buffered yet (causing previous buffering to get cancelled), example repo here for reproduction.
It gets weird though, when run behind nginx every request triggers the error. I haven't had time to investigate this, but it occurred on multiple machines with different nginx configurations, which certainly shouldn't cause all requests to get cancelled.
Related: #12325
The text was updated successfully, but these errors were encountered: