0

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.

Def_NulL
  • 87
  • 4

1 Answers1

0

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).

Marek
  • 3,471
  • 1
  • 16
  • 15
  • terminated() would not be called if gen_server would be killed using erlang:exit(GenServerPid, kill) or if the brutal_kill strategy of the supervisor is used. Any way if there is no solution without breaking the encapsulation I will use the one which I mention above. – Def_NulL Oct 03 '12 at 11:52