Browse code

core: tcp - log details of the exiting tcp connection on insert failure

Daniel-Constantin Mierla authored on 03/06/2020 10:45:05
Showing 1 changed files
... ...
@@ -1720,7 +1720,7 @@ static ticks_t tcpconn_read_timeout(ticks_t t, struct timer_ln* tl, void* data)
1720 1720
  *          idx - index in the fd_array (or -1 if not known)
1721 1721
  * return: -1 on error, or when we are not interested any more on reads
1722 1722
  *            from this fd (e.g.: we are closing it )
1723
- *          0 on EAGAIN or when by some other way it is known that no more 
1723
+ *          0 on EAGAIN or when by some other way it is known that no more
1724 1724
  *            io events are queued on the fd (the receive buffer is empty).
1725 1725
  *            Usefull to detect when there are no more io events queued for
1726 1726
  *            sigio_rt, epoll_et, kqueue.
... ...
@@ -1728,7 +1728,7 @@ static ticks_t tcpconn_read_timeout(ticks_t t, struct timer_ln* tl, void* data)
1728 1728
  *            queued -- the receive buffer might still be non-empty)
1729 1729
  */
1730 1730
 inline static int handle_io(struct fd_map* fm, short events, int idx)
1731
-{	
1731
+{
1732 1732
 	int ret;
1733 1733
 	int n;
1734 1734
 	int read_flags;
... ...
@@ -1736,10 +1736,11 @@ inline static int handle_io(struct fd_map* fm, short events, int idx)
1736 1736
 	int s;
1737 1737
 	long resp;
1738 1738
 	ticks_t t;
1739
-	
1739
+	fd_map_t *ee = NULL;
1740
+
1740 1741
 	/* update the local config */
1741 1742
 	cfg_update();
1742
-	
1743
+
1743 1744
 	switch(fm->type){
1744 1745
 		case F_TCPMAIN:
1745 1746
 again:
... ...
@@ -1803,7 +1804,7 @@ repeat_1st_read:
1803 1804
 			if (unlikely(read_flags & RD_CONN_REPEAT_READ))
1804 1805
 				goto repeat_1st_read;
1805 1806
 #endif /* USE_TLS */
1806
-			
1807
+
1807 1808
 			/* must be before io_watch_add, io_watch_add might catch some
1808 1809
 			 * already existing events => might call handle_io and
1809 1810
 			 * handle_io might decide to del. the new connection =>
... ...
@@ -1816,13 +1817,25 @@ repeat_1st_read:
1816 1817
 			local_timer_reinit(&con->timer);
1817 1818
 			local_timer_add(&tcp_reader_ltimer, &con->timer,
1818 1819
 								S_TO_TICKS(TCP_CHILD_TIMEOUT), t);
1819
-			if (unlikely(io_watch_add(&io_w, s, POLLIN, F_TCPCONN, con)<0)){
1820
+			if (unlikely(io_watch_add(&io_w, s, POLLIN, F_TCPCONN, con)<0)) {
1820 1821
 				LM_CRIT("io_watch_add failed for %p id %d fd %d, state %d, flags %x,"
1821 1822
 							" main fd %d, refcnt %d ([%s]:%u -> [%s]:%u)\n",
1822 1823
 							con, con->id, con->fd, con->state, con->flags,
1823 1824
 							con->s, atomic_get(&con->refcnt),
1824 1825
 							ip_addr2a(&con->rcv.src_ip), con->rcv.src_port,
1825 1826
 							ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port);
1827
+				ee = get_fd_map(&io_w, s);
1828
+				if(ee!=0 && ee->type==F_TCPCONN) {
1829
+					tcp_connection_t *ec;
1830
+					ec = (tcp_connection_t*)ee->data;
1831
+					LM_CRIT("existing tcp con %p id %d fd %d, state %d, flags %x,"
1832
+							" main fd %d, refcnt %d ([%s]:%u -> [%s]:%u)\n",
1833
+							ec, ec->id, ec->fd, ec->state, ec->flags,
1834
+							ec->s, atomic_get(&ec->refcnt),
1835
+							ip_addr2a(&ec->rcv.src_ip), ec->rcv.src_port,
1836
+							ip_addr2a(&ec->rcv.dst_ip), ec->rcv.dst_port);
1837
+
1838
+				}
1826 1839
 				tcpconn_listrm(tcp_conn_lst, con, c_next, c_prev);
1827 1840
 				local_timer_del(&tcp_reader_ltimer, &con->timer);
1828 1841
 				goto con_error;