elixir-plug / plug_cowboy

Plug adapter for the Cowboy web server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

DmitryKakurin opened this issue · comments

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!

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!

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