Index: b/res/res_rtp_asterisk.c
===================================================================
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -3340,6 +3340,13 @@ static int __rtp_recvfrom(struct ast_rtp
 		dtls_srtp_stop_timeout_timer(instance, rtp, rtcp);
 		ao2_lock(instance);
 
+		/* Test SSL again after unlock to avoid race */
+		if (!dtls->ssl) {
+			ast_log(LOG_ERROR, "SSL session in RTP instance %p disappeared after unlock\n",
+				instance);
+			return -1;
+		}
+
 		/* If we don't yet know if we are active or passive and we receive a packet... we are obviously passive */
 		if (dtls->dtls_setup == AST_RTP_DTLS_SETUP_ACTPASS) {
 			dtls->dtls_setup = AST_RTP_DTLS_SETUP_PASSIVE;
