浏览代码

core: tcp - more details on error log messages

Daniel-Constantin Mierla 5 年之前
父节点
当前提交
fefb3f1b2d
共有 2 个文件被更改,包括 33 次插入27 次删除
  1. 28 25
      src/core/io_wait.h
  2. 5 2
      src/core/tcp_read.c

+ 28 - 25
src/core/io_wait.h

@@ -415,13 +415,13 @@ inline static int io_watch_add(	io_wait_h* h,
 			 */
 			/* set async & signal */
 			if (fcntl(fd, F_SETOWN, my_pid())==-1){
-				LM_ERR("fnctl: SETOWN failed: %s [%d]\n",
-					strerror(errno), errno);
+				LM_ERR("fnctl: SETOWN on fd %d failed: %s [%d]\n",
+					fd, strerror(errno), errno);
 				goto error;
 			}
 			if (fcntl(fd, F_SETSIG, h->signo)==-1){
-				LM_ERR("fnctl: SETSIG failed: %s [%d]\n",
-					strerror(errno), errno);
+				LM_ERR("fnctl: SETSIG on fd %d failed: %s [%d]\n",
+					fd, strerror(errno), errno);
 				goto error;
 			}
 			/* set both non-blocking and async */
@@ -455,7 +455,8 @@ again1:
 			n=epoll_ctl(h->epfd, EPOLL_CTL_ADD, fd, &ep_event);
 			if (unlikely(n==-1)){
 				if (errno==EAGAIN) goto again1;
-				LM_ERR("epoll_ctl failed: %s [%d]\n", strerror(errno), errno);
+				LM_ERR("epoll_ctl on fd %d failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 				goto error;
 			}
 			break;
@@ -475,7 +476,8 @@ again2:
 			n=epoll_ctl(h->epfd, EPOLL_CTL_ADD, fd, &ep_event);
 			if (unlikely(n==-1)){
 				if (errno==EAGAIN) goto again2;
-				LM_ERR("epoll_ctl failed: %s [%d]\n", strerror(errno), errno);
+				LM_ERR("epoll_ctl on fd %d failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 				goto error;
 			}
 			break;
@@ -505,8 +507,8 @@ again2:
 again_devpoll:
 			if (write(h->dpoll_fd, &pfd, sizeof(pfd))==-1){
 				if (errno==EAGAIN) goto again_devpoll;
-				LM_ERR("/dev/poll write failed: %s [%d]\n",
-					strerror(errno), errno);
+				LM_ERR("/dev/poll write of fd %d failed: %s [%d]\n",
+					fd, strerror(errno), errno);
 				goto error;
 			}
 			break;
@@ -532,7 +534,8 @@ check_io_again:
 				(pf.revents & (e->events|POLLERR|POLLHUP)));
 		if (unlikely(e->type && (n==-1))){
 			if (errno==EINTR) goto check_io_again;
-			LM_ERR("check_io poll: %s [%d]\n", strerror(errno), errno);
+			LM_ERR("check_io poll on fd %d failed: %s [%d]\n",
+					fd, strerror(errno), errno);
 		}
 	}
 #endif
@@ -637,13 +640,13 @@ inline static int io_watch_del(io_wait_h* h, int fd, int idx, int flags)
 				/* reset ASYNC */
 				fd_flags=fcntl(fd, F_GETFL);
 				if (unlikely(fd_flags==-1)){
-					LM_ERR("fnctl: GETFL failed: %s [%d]\n",
-						strerror(errno), errno);
+					LM_ERR("fnctl: GETFL on fd %d failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 					goto error;
 				}
 				if (unlikely(fcntl(fd, F_SETFL, fd_flags&(~O_ASYNC))==-1)){
-					LM_ERR("fnctl: SETFL failed: %s [%d]\n",
-						strerror(errno), errno);
+					LM_ERR("fnctl: SETFL on fd %d failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 					goto error;
 				}
 			fix_fd_array; /* only on success */
@@ -664,8 +667,8 @@ again_epoll:
 				n=epoll_ctl(h->epfd, EPOLL_CTL_DEL, fd, &ep_event);
 				if (unlikely(n==-1)){
 					if (errno==EAGAIN) goto again_epoll;
-					LM_ERR("removing fd from epoll list failed: %s [%d]\n",
-						strerror(errno), errno);
+					LM_ERR("removing fd %d from epoll list failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 					goto error;
 				}
 #ifdef EPOLL_NO_CLOSE_BUG
@@ -704,8 +707,8 @@ again_epoll:
 again_devpoll:
 				if (write(h->dpoll_fd, &pfd, sizeof(pfd))==-1){
 					if (errno==EINTR) goto again_devpoll;
-					LM_ERR("removing fd from /dev/poll failed: %s [%d]\n",
-						strerror(errno), errno);
+					LM_ERR("removing fd %d from /dev/poll failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 					goto error;
 				}
 				break;
@@ -831,8 +834,8 @@ again_epoll_lt:
 				n=epoll_ctl(h->epfd, EPOLL_CTL_MOD, fd, &ep_event);
 				if (unlikely(n==-1)){
 					if (errno==EAGAIN) goto again_epoll_lt;
-					LM_ERR("modifying epoll events failed: %s [%d]\n",
-						strerror(errno), errno);
+					LM_ERR("modifying epoll events of fd %d failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 					goto error;
 				}
 			break;
@@ -851,8 +854,8 @@ again_epoll_et:
 				n=epoll_ctl(h->epfd, EPOLL_CTL_MOD, fd, &ep_event);
 				if (unlikely(n==-1)){
 					if (errno==EAGAIN) goto again_epoll_et;
-					LM_ERR("modifying epoll events failed: %s [%d]\n",
-						strerror(errno), errno);
+					LM_ERR("modifying epoll events of fd %d failed: %s [%d]\n",
+						fd, strerror(errno), errno);
 					goto error;
 				}
 			break;
@@ -887,8 +890,8 @@ again_epoll_et:
 again_devpoll1:
 				if (unlikely(write(h->dpoll_fd, &pfd, sizeof(pfd))==-1)){
 					if (errno==EINTR) goto again_devpoll1;
-					LM_ERR("removing fd from /dev/poll failed: %s [%d]\n",
-								strerror(errno), errno);
+					LM_ERR("removing fd %d from /dev/poll failed: %s [%d]\n",
+								fd, strerror(errno), errno);
 					goto error;
 				}
 again_devpoll2:
@@ -896,8 +899,8 @@ again_devpoll2:
 				pfd.revents=0;
 				if (unlikely(write(h->dpoll_fd, &pfd, sizeof(pfd))==-1)){
 					if (errno==EINTR) goto again_devpoll2;
-					LM_ERR("re-adding fd to /dev/poll failed: %s [%d]\n",
-								strerror(errno), errno);
+					LM_ERR("re-adding fd %d to /dev/poll failed: %s [%d]\n",
+								fd, strerror(errno), errno);
 					/* error re-adding the fd => mark it as removed/unhash */
 					unhash_fd_map(e);
 					goto error;

+ 5 - 2
src/core/tcp_read.c

@@ -1846,8 +1846,11 @@ repeat_1st_read:
 			if (unlikely(con->state==S_CONN_BAD)){
 				resp=CONN_ERROR;
 				if (!(con->send_flags.f & SND_F_CON_CLOSE))
-					LM_WARN("F_TCPCONN connection marked as bad: %p id %d refcnt %d\n",
-							con, con->id, atomic_get(&con->refcnt));
+					LM_WARN("F_TCPCONN connection marked as bad: %p id %d fd %d"
+							" refcnt %d ([%s]:%u -> [%s]:%u)\n",
+							con, con->id, con->fd, atomic_get(&con->refcnt),
+							ip_addr2a(&con->rcv.src_ip), con->rcv.src_port,
+							ip_addr2a(&con->rcv.dst_ip), con->rcv.dst_port);
 				goto read_error;
 			}
 			read_flags=((