websock_adapter icon indicating copy to clipboard operation
websock_adapter copied to clipboard

Missing function clause in terminate callback (cowboy adapter)

Open focused opened this issue 4 months ago • 6 comments

When I got an error the terminate callback can not handle it correctly:

"** (FunctionClauseError) no function clause matching in WebSockAdapter.CowboyAdapter.terminate/3\n    (websock_adapter 0.5.7) lib/websock_adapter/cowboy_adapter.ex:52: 

WebSockAdapter.CowboyAdapter.terminate({:crash, :error, :function_clause}, %{port: 443, scheme: \"https\", version: :\"HTTP/1.1\", path: \"*****\", host: \"*****\", peer: {{*, *, *, *}, *}, method: \"GET\", qs: \"\"}, {MyWSHandler, %{}, %MyWSHandler.State{...}})
...

Source: https://github.com/phoenixframework/websock_adapter/blob/c4c6ea66a1d65436be869abc6224b90317e4950a/lib/websock_adapter/cowboy_adapter.ex#L71

It looks like the terminate callback awaits 2-elem tuple in the 3rd argument: terminate(reason, _req, {handler, state}), but there are 3 elements - ws handler module, some empty map (%{}) and the WS handler state.

Package versions:

cowboy "2.11.0"
plug "1.16.1"
plug_cowboy "2.6.2"
websock "0.5.3"
websock_adapter "0.5.7"
elixir 1.15.6-otp-26
erlang 26.1.1

focused avatar Oct 07 '24 09:10 focused