Hackney connection references in process library

80 views
Skip to first unread message

Eric Goodwin

unread,
Aug 8, 2016, 12:59:23 PM8/8/16
to elixir-lang-talk
I am using poolboy to manage a pool of search workers. 
Each search worker is a genserver and has a hackney connection in it's state. For some reason, we're getting a leak where hackney is keeping connections open. The search processes only have the one connection in the state, but can have quite a few connections in it's process library. 

Here are main parts of the Search module.

Any ideas why we'd be getting a leak with connections staying open in the process library?
Thanks!





José Valim

unread,
Aug 8, 2016, 7:44:16 PM8/8/16
to elixir-l...@googlegroups.com
There are a couple questions you should ask yourself:

1. Why are you trapping exists?

2. What happens when the worker dies?

3. What happens when the connection dies?

4. I believe hackney already ships with its own pools, can't you use them?

In any case, it seems your code does not link the worker process with the connection process. This means that, if the worker is suddenly killed, the connection will leak. However, given you are trapping exists, I believe it can only happen if the :kill message is used to kill the worker process (which is something supervisors may use).

If you really need your own pool, the simplest solution would be to remove the trapping of exits and link the two processes. This way you answer question by not trapping and you guarantee the worker will die when the connection dies and vice-versa.




José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/7436695e-b28b-4ba2-9a9d-efaa47d3dde6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Goodwin

unread,
Aug 9, 2016, 5:42:09 PM8/9/16
to elixir-l...@googlegroups.com, José Valim
Thanks for your reply José.

I’m trapping the exits so I can make sure the connection gets closed if the worker is terminated for any reason.

When the worker dies, I expect that terminate will get called, which should then close the connection.

The connection doesn’t look to be another process, but a reference that is used as a key in the process dictionary to get the state of that connection. Inside that state we have the socket (Port). If the worker dies, it should take the port down with it.

I’m not using the Hackney pool because we want to parallelize the processing and building of responses on the worker. 

The Fix:

It looks like I was able to get it to stop leaking by manually closing the connection when an {:error, :closed} tuple is returned.


I was expecting that if the client returned {:error, :closed}, it would have closed the port, but it looks like that’s not the case.

Thanks again for replying. There were some good suggestions of things to look into and it was a help.

Cheers,
Eric Goodwin
You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-talk/lVhDSabpyjo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/CAGnRm4%2Bt665kpVxSA_YroZf83tKSNwuiEg4pp7uMxL%2BZxiB1tA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages