[erlang-questions] Why does adding an io:format call make my accept socket remain valid?
Nathaniel Waisbrot
nathaniel@REDACTED
Sun Mar 27 06:45:46 CEST 2016
I don't know about your garbage-collection question, but:
> Why does that io:format/3 call (only when after the spawn/3 call) keep the socket open and active for the spawned process? I wouldn't expect it to be garbage collected because the spawned process holds a reference to it (and even adding it to the State in the return doesn't fix it). Only other thing I could think of was that handle_cast is run in it's own process which closes the socket when it dies (since it has ownership), but that doesn't make sense from what I've read about OTP.
Normally handle_cast would be run in the gen_server's process (since that's the whole point), but it looks to me like in your test:
> spawn_link(fun () -> tcp_listener_server:handle_cast(accept, State) end),
you are bypassing gen_server and instead ... telling handle_cast to run in its own one-off process.
Do you mean to be doing this? In your test code, you could call gen_server:start/1 and then gen_server:cast/2 and get the actual gen_server behavior.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160327/0459d512/attachment.bin>
More information about the erlang-questions
mailing list