Index: b/res/res_rtp_asterisk.c
===================================================================
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -1037,8 +1037,8 @@ static int ice_reset_session(struct ast_
 	 * we need to destroy that TURN socket.
 	 */
 	if (rtp->ice_num_components == 1 && rtp->turn_rtcp) {
-		struct timeval wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
-		struct timespec ts = { .tv_sec = wait.tv_sec, .tv_nsec = wait.tv_usec * 1000, };
+		struct timeval wait;
+		struct timespec ts;
 
 		rtp->turn_state = PJ_TURN_STATE_NULL;
 
@@ -1047,6 +1047,9 @@ static int ice_reset_session(struct ast_
 		pj_turn_sock_destroy(rtp->turn_rtcp);
 		ao2_lock(instance);
 		while (rtp->turn_state != PJ_TURN_STATE_DESTROYING) {
+			wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
+			ts.tv_sec = wait.tv_sec;
+			ts.tv_nsec = wait.tv_usec * 1000;
 			ast_cond_timedwait(&rtp->cond, ao2_object_get_lockaddr(instance), &ts);
 		}
 	}
@@ -1648,8 +1651,8 @@ static void ast_rtp_ice_turn_request(str
 	pj_str_t turn_addr;
 	struct ast_sockaddr addr = { { 0, } };
 	pj_stun_config stun_config;
-	struct timeval wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
-	struct timespec ts = { .tv_sec = wait.tv_sec, .tv_nsec = wait.tv_usec * 1000, };
+	struct timeval wait;
+	struct timespec ts;
 	pj_turn_session_info info;
 	struct ast_sockaddr local, loop;
 	pj_status_t status;
@@ -1697,6 +1700,9 @@ static void ast_rtp_ice_turn_request(str
 		pj_turn_sock_destroy(*turn_sock);
 		ao2_lock(instance);
 		while (rtp->turn_state != PJ_TURN_STATE_DESTROYING) {
+			wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
+			ts.tv_sec = wait.tv_sec;
+			ts.tv_nsec = wait.tv_usec * 1000;
 			ast_cond_timedwait(&rtp->cond, ao2_object_get_lockaddr(instance), &ts);
 		}
 	}
@@ -1757,12 +1763,36 @@ static void ast_rtp_ice_turn_request(str
 	 * Because the TURN socket is asynchronous and we are synchronous we need to
 	 * wait until it is done
 	 */
+	pj_turn_state_t current_turn_state, new_turn_state;
 	while (rtp->turn_state < PJ_TURN_STATE_READY) {
+		wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
+		ts.tv_sec = wait.tv_sec;
+		ts.tv_nsec = wait.tv_usec * 1000;
+
+		current_turn_state = rtp->turn_state;
 		ast_cond_timedwait(&rtp->cond, ao2_object_get_lockaddr(instance), &ts);
+		new_turn_state = rtp->turn_state;
+
+		if (current_turn_state == new_turn_state) {
+			/* if turn state did not change it (most probably) means that it exited from
+			ast_cond_timedwait because it waited the maximum time
+			In this case we want to exit.
+			*/
+			ast_debug_ice(2, "(%p) ICE request TURN: turn state did not change (%d -> %d) ; this is a timeout ; exiting)\n",
+						  instance, current_turn_state, new_turn_state);
+			break;
+		}
+		else {
+			ast_debug_ice(2, "(%p) ICE request TURN: turn state changed from %d to %d\n",
+						  instance, current_turn_state, new_turn_state);
+			continue;
+		}
 	}
 
 	/* If a TURN session was allocated add it as a candidate */
 	if (rtp->turn_state != PJ_TURN_STATE_READY) {
+		ast_log(LOG_ERROR, "(%p) Failed to request TURN server (rtp->turn_state:%d)\n",
+			instance, rtp->turn_state);
 		return;
 	}
 
@@ -4118,8 +4148,8 @@ static void rtp_deallocate_transport(str
 {
 	int saved_rtp_s = rtp->s;
 #ifdef HAVE_PJPROJECT
-	struct timeval wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
-	struct timespec ts = { .tv_sec = wait.tv_sec, .tv_nsec = wait.tv_usec * 1000, };
+	struct timeval wait;
+	struct timespec ts;
 #endif
 
 #if defined(HAVE_OPENSSL) && (OPENSSL_VERSION_NUMBER >= 0x10001000L) && !defined(OPENSSL_NO_SRTP)
@@ -4156,6 +4186,9 @@ static void rtp_deallocate_transport(str
 		pj_turn_sock_destroy(rtp->turn_rtp);
 		ao2_lock(instance);
 		while (rtp->turn_state != PJ_TURN_STATE_DESTROYING) {
+			wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
+			ts.tv_sec = wait.tv_sec;
+			ts.tv_nsec = wait.tv_usec * 1000;
 			ast_cond_timedwait(&rtp->cond, ao2_object_get_lockaddr(instance), &ts);
 		}
 		rtp->turn_rtp = NULL;
@@ -4170,6 +4203,9 @@ static void rtp_deallocate_transport(str
 		pj_turn_sock_destroy(rtp->turn_rtcp);
 		ao2_lock(instance);
 		while (rtp->turn_state != PJ_TURN_STATE_DESTROYING) {
+			wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
+			ts.tv_sec = wait.tv_sec;
+			ts.tv_nsec = wait.tv_usec * 1000;
 			ast_cond_timedwait(&rtp->cond, ao2_object_get_lockaddr(instance), &ts);
 		}
 		rtp->turn_rtcp = NULL;
