Index: /pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 5520)
+++ /pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 5521)
@@ -1837,4 +1837,9 @@
     tp_ice = (struct transport_ice*) pj_ice_strans_get_user_data(ice_st);
 
+    pj_perror(5, tp_ice->base.name, result, "ICE operation complete"
+	      " (op=%d%s)", op,
+	      (op==PJ_ICE_STRANS_OP_INIT? "/initialization" :
+	      (op==PJ_ICE_STRANS_OP_NEGOTIATION? "/negotiation":"")));
+
     /* Notify application */
     if (tp_ice->cb.on_ice_complete)
Index: /pjproject/trunk/pjnath/src/pjnath/ice_strans.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 5520)
+++ /pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 5521)
@@ -377,5 +377,5 @@
 	cand->status = PJ_EPENDING;
 	cand->local_pref = RELAY_PREF;
-	cand->transport_id = CREATE_TP_ID(TP_TURN, idx);
+	cand->transport_id = tp_id;
 	cand->comp_id = (pj_uint8_t) comp->comp_id;
     }
@@ -414,6 +414,7 @@
 
     PJ_LOG(4,(ice_st->obj_name,
-		  "Comp %d: TURN relay candidate waiting for allocation",
-		  comp->comp_id));
+		  "Comp %d/%d: TURN relay candidate (tpid=%d) "
+		  "waiting for allocation",
+		  comp->comp_id, comp->cand_cnt-1, cand->transport_id));
 
     return PJ_SUCCESS;
@@ -516,6 +517,7 @@
 
 	PJ_LOG(4,(ice_st->obj_name,
-		  "Comp %d: srflx candidate starts Binding discovery",
-		  comp->comp_id));
+		  "Comp %d: srflx candidate (tpid=%d) starts "
+		  "Binding discovery",
+		  comp->comp_id, cand->transport_id));
 
 	pj_log_push_indent();
@@ -623,7 +625,7 @@
 	    if (cand_duplicate) {
 		PJ_LOG(4, (ice_st->obj_name,
-		       "Comp %d: host candidate %s is a duplicate",
+		       "Comp %d: host candidate %s (tpid=%d) is a duplicate",
 		       comp->comp_id, pj_sockaddr_print(&cand->addr, addrinfo,
-		       sizeof(addrinfo), 3)));
+		       sizeof(addrinfo), 3), cand->transport_id));
 
 		pj_bzero(&cand->addr, sizeof(cand->addr));
@@ -638,7 +640,9 @@
 
 	    PJ_LOG(4,(ice_st->obj_name,
-		      "Comp %d: host candidate %s added",
-		      comp->comp_id, pj_sockaddr_print(&cand->addr, addrinfo,
-						      sizeof(addrinfo), 3)));
+		      "Comp %d/%d: host candidate %s (tpid=%d) added",
+		      comp->comp_id, comp->cand_cnt-1, 
+		      pj_sockaddr_print(&cand->addr, addrinfo,
+					sizeof(addrinfo), 3),
+					cand->transport_id));
 	}
     }
@@ -941,11 +945,20 @@
 	 * have not been created.
 	 */
-	if (!comp || comp->creating) return;
+	if (!comp || comp->creating) {
+	    PJ_LOG(5, (ice_st->obj_name, "ICE init update: creating comp %d",
+		       (comp?comp->comp_id:(i+1)) ));
+	    return;
+	}
 
 	for (j=0; j<comp->cand_cnt; ++j) {
 	    pj_ice_sess_cand *cand = &comp->cand_list[j];
 
-	    if (cand->status == PJ_EPENDING)
+	    if (cand->status == PJ_EPENDING) {
+		PJ_LOG(5, (ice_st->obj_name, "ICE init update: "
+			   "comp %d/%d[%s] is pending",
+			   comp->comp_id, j,
+			   pj_ice_get_cand_type_name(cand->type)));
 		return;
+	    }
 	}
     }
@@ -1957,5 +1970,5 @@
 	char ipaddr[PJ_INET6_ADDRSTRLEN+8];
 	pj_ice_sess_cand *cand = NULL;
-	unsigned i;
+	unsigned i, cand_idx = 0xFF;
 
 	comp->turn[tp_idx].err_cnt = 0;
@@ -1973,4 +1986,5 @@
 	    {
 		cand = &comp->cand_list[i];
+		cand_idx = i;
 		break;
 	    }
@@ -2008,6 +2022,7 @@
 
 	PJ_LOG(4,(comp->ice_st->obj_name,
-		  "Comp %d: TURN allocation complete, relay address is %s",
-		  comp->comp_id,
+		  "Comp %d/%d: TURN allocation (tpid=%d) complete, "
+		  "relay address is %s",
+		  comp->comp_id, cand_idx, cand->transport_id,
 		  pj_sockaddr_print(&rel_info.relay_addr, ipaddr,
 				     sizeof(ipaddr), 3)));
@@ -2020,5 +2035,5 @@
     {
 	pj_ice_sess_cand *cand = NULL;
-	unsigned i;
+	unsigned i, cand_idx = 0xFF;
 
 	/* DNS resolution or TURN transport creation/allocation
@@ -2040,4 +2055,5 @@
 	    {
 		cand = &comp->cand_list[i];
+		cand_idx = i;
 		break;
 	    }
@@ -2050,5 +2066,10 @@
 	 * to the list.
 	 */
-	if (cand) cand->status = PJ_ERESOLVE;
+	if (cand) {
+	    cand->status = PJ_ERESOLVE;
+	    PJ_LOG(4,(comp->ice_st->obj_name,
+		      "Comp %d/%d: TURN resolving (tpid=%d) failed",
+		      comp->comp_id, cand_idx, cand->transport_id));
+	}
 
 	sess_init_update(comp->ice_st);
Index: /pjproject/trunk/pjnath/src/pjnath/turn_sock.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/turn_sock.c	(revision 5520)
+++ /pjproject/trunk/pjnath/src/pjnath/turn_sock.c	(revision 5521)
@@ -429,4 +429,12 @@
 	pj_grp_lock_release(turn_sock->grp_lock);
 	return status;
+    } else if (!turn_sock->sess) {
+	/* TURN session may have been destroyed here, i.e: when DNS resolution
+	 * completed synchronously and TURN allocation failed.
+	 */
+	PJ_LOG(4,(turn_sock->obj_name, "TURN session destroyed in setting "
+				       "TURN server"));
+	pj_grp_lock_release(turn_sock->grp_lock);
+	return PJ_EGONE;
     }
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5520)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 5521)
@@ -1742,4 +1742,7 @@
         call->med_ch_mutex = NULL;
     }
+
+    PJ_PERROR(5,(THIS_FILE, status,
+		 "Call %d: media transport initialization complete", call_id));
 
     if (status != PJ_SUCCESS) {
