mtrudel / bandit

Bandit is a pure Elixir HTTP server for Plug & WebSock applications
MIT License
1.68k stars 82 forks source link

Request keeps running after client hangs up #408

Open joladev opened 4 days ago

joladev commented 4 days ago

We're experimenting with switching over to Bandit but we're struggling with this issue where if a long running request is closed by the GCP load balancer, and the client gets a 502 response, the Bandit/Thousand Island request process is still running and executing the code. Once it reaches the end and tries to send the response, it errors with Bandit.HTTPTransport.Bandit.HTTP1.Socket.request_error!/2: closed.

The expected behavior would be for the code to stop running the moment the load balancer or the client hang up, and that's also the behavior we're seeing from cowboy

I am not able to reproduce it locally without the load balancer, so I'm guessing it's related to keep alive. I'd be happy to provide more information or try out a patch

joladev commented 4 days ago

To give an update on this, I can replicate this running locally so I guess the load balancer was a red herring. Made a repo to reproduce it, just a phoenix template and some logs and Process.sleep. Instructions in the readme but basically start a request and then give up on the client side, you'll see the server side continue working even though there's no one there to get the response anymore.

https://github.com/joladev/hangups