<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hello,</div><div class=""><br class=""></div><div class="">As far, I’ve understood from you explantation... We have a following “sequence” of operations when accepting socket and upgrading a connection to ssl:</div><div class=""><br class=""></div><div class="">A. ssl:transport_accept(...)</div><div class="">B. ssl:ssl_accept(...)</div><div class="">C. ssl:setopts(…, [{active, once}])</div><div class=""><br class=""></div><div class="">Before (C) socket in passive mode. No one guarantees that {ssl_closed, …} is delivered to you. Therefore, you need to check error codes of each socket operation and react in correspond manner. E.g. if connection is dropped between B and C then return you an error. </div><div class=""><br class=""></div><div class="">— CLIP — </div><div class=""><p style="padding: 0px; margin: 7px 0px 12px; color: rgb(34, 34, 34); line-height: 17.549999237060547px; font-family: verdana, Arial, sans-serif;" class="">When an SSL socket is in active mode (the default), data from the socket is delivered to the owner of the socket in the form of messages:</p><list type="bulleted" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: verdana, Arial, sans-serif;" class=""><item style="padding: 0px; margin: 0px;" class=""><p style="padding: 0px; margin: 7px 0px 12px; line-height: 17.549999237060547px;" class=""><code style="padding: 0px; margin: 0px; font-family: "Courier New", "Andale Mono", monospace; background-image: none; background-attachment: scroll; background-color: rgb(238, 255, 204); border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: rgb(170, 221, 153); background-position: 0px 0px; background-repeat: repeat repeat;" class="">{ssl, Socket, Data}</code></p></item><item style="padding: 0px; margin: 0px;" class=""><p style="padding: 0px; margin: 7px 0px 12px; line-height: 17.549999237060547px;" class=""><code style="padding: 0px; margin: 0px; font-family: "Courier New", "Andale Mono", monospace; background-image: none; background-attachment: scroll; background-color: rgb(238, 255, 204); border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: rgb(170, 221, 153); background-position: 0px 0px; background-repeat: repeat repeat;" class="">{ssl_closed, Socket}</code></p></item><item style="padding: 0px; margin: 0px;" class=""><p style="padding: 0px; margin: 7px 0px 12px; line-height: 17.549999237060547px;" class=""><code style="padding: 0px; margin: 0px; font-family: "Courier New", "Andale Mono", monospace; background-image: none; background-attachment: scroll; background-color: rgb(238, 255, 204); border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: rgb(170, 221, 153); background-position: 0px 0px; background-repeat: repeat repeat;" class="">{ssl_error, Socket, Reason}</code></p></item></list></div><div class="">— CLIP — </div><div class=""> </div><div class="">Best Regards, </div><div class="">Dmitry</div><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 15 Feb 2018, at 13.23, Roger Lipscombe <<a href="mailto:roger@differentpla.net" class="">roger@differentpla.net</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">OK. Let me rephrase that:<br class=""><br class="">- {active, once} obviously has something in place to handle data<br class="">arriving and closed sockets *in between* calls to {active, once} --<br class="">i.e. it'll be {active, false} for a brief interval. I last looked at<br class="">this code in 17.x (before the gen_statem refactoring), so I'm not sure<br class="">where it lives now.<br class="">- does it deal correctly with closed sockets that close before the<br class="">*first* call to {active, once}? In other words: can I expect an<br class="">ssl_closed message in this case? Is there something special about the<br class="">first call?<br class=""><br class="">On 15 February 2018 at 11:15, Dmitry Kolesnikov <<a href="mailto:dmkolesnikov@gmail.com" class="">dmkolesnikov@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class="">Hello,<br class=""><br class="">On 15 Feb 2018, at 13.08, Roger Lipscombe <<a href="mailto:roger@differentpla.net" class="">roger@differentpla.net</a>> wrote:<br class=""><br class="">The only thing I can think of is that the socket is being closed<br class="">between ranch:accept_ack and Transport:setopts, and Erlang's not<br class="">sending the ssl_closed message. Does this sound likely? How do I deal<br class="">with this?<br class=""><br class=""><br class="">No, it does not sound likely! The bug is either at ranch or your code.<br class=""><br class="">I think you should try to verify the result of each socket operation before<br class="">going further on. I am referring here to your statement: I'm *not* verifying<br class="">the result.<br class=""><br class=""><br class="">Best Regards,<br class="">Dmitry<br class=""></blockquote></div></div></blockquote></div><br class=""></body></html>