0
votes

I'm developing an erlang app which use both cowboy and sockjs and I wonder if is it possible to link with the cowboy process which handles the websocket connection?

Right now process with gen_server behaviour is associated with each websocet conenction. Such process stores Conn instance in init and when the client closes connection this process is terminated from websocket handler, and if the gen_server process is terminated the Conn:close is called from the terminate() of gen_server which do the cleanup. It works, but I don'l like this solution, because there are several cases when even with trap_exit enabled terminate function would not be called, so if linking is possible it would be better and simplier solution.

1

1 Answers

0
votes

In what cases terminate won't be called on gen_server?

In theory you can extract Pid from Conn object, but that obviously breaks encapsulation.

Feel free to submit a pull request if you can propose a sane API that solves your problem (and please do explain the problem in details in the pull request).