elixir-plug / plug_cowboy

Plug adapter for the Cowboy web server
Other
243 stars 48 forks source link

Should `Plug.Cowboy.Handler` implement cowboy's `terminate` callback? #74

Closed DmitryKakurin closed 3 years ago

DmitryKakurin commented 3 years ago

I have a problem in my web application: some clients don't wait for HTTP response and disconnect early. As a result, the erlang process executing this request on my server terminates instantly, while I need to do some resource cleanup when it happens.

So I need some callback to be called on my Plug to notify me of client closing connection before termination.

Please advise if it's already possible, thanks!

josevalim commented 3 years ago

Cowboy provides the concepts of stream handlers, so you can use them to hook into the connection lifecycle. More info here: https://ninenines.eu/docs/en/cowboy/2.9/manual/cowboy_stream/ You can configure them here: https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html

Btw, next time please use the ElixirForum or StackOverflow for questions/help/feedback, where a wider community will be able to help you. We reserve the issues tracker for issues only. Thank you!

DmitryKakurin commented 3 years ago

Thank you! And I'll use the forum next time.