Index: chan_sip.c =================================================================== --- chan_sip.c (revision 316037) +++ chan_sip.c (working copy) @@ -13261,6 +13261,34 @@ int start = 0; int wildcard_found = 0; int single_binding_found = 0; + + + + /* check if we have already a tcp connection */ + if(!ast_sockaddr_isnull(&peer->addr) && peer->socket.type != SIP_TRANSPORT_UDP){ + /* if the remote address is not me, close this tcp helper thread */ + if(ast_sockaddr_cmp_addr(&peer->addr, &pvt->recv)){ + if (peer->socket.tcptls_session) { + struct sip_threadinfo *th; + + struct sip_threadinfo tmp = { + .tcptls_session = peer->socket.tcptls_session, + }; + + /* search for the tcp_helper_thread */ + th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"); + if(th){ + /* stopping the thread also closes socket an destroy it */ + ao2_t_ref(th, -1, "Decrementing threadinfo from callback"); + pthread_t thread = th->threadid; + th->stop = 1; + pthread_kill(thread, SIGURG); + pthread_join(thread, NULL); + } + } + } + } /* end; search for older tcp connection */ + ast_copy_string(contact, __get_header(req, "Contact", &start), sizeof(contact));