I encountered a problem in receiving tls packets in my application.
After some investigation, I figured out that the process has a tls packet in it's message queue but didn't have a chance to handle it. This happens in a specific situation when the server closes the connection after sending large data which is split into several packets so that some of them remain in the message queue when the socket closes by FIN.
I followed OTP code and applied a patch below and confirmed it solved the problem. But I'm not quite sure if this is the right way to solve the problem nor why it was written that way in the first place -- dtls_connection seems to be working just as my patch.