Browse code

- "catch bug" code (at least report it and try to recover)

Andrei Pelinescu-Onciul authored on 05/11/2003 20:20:13
Showing 3 changed files
... ...
@@ -43,7 +43,7 @@ export makefile_defs
43 43
 VERSION = 0
44 44
 PATCHLEVEL = 8
45 45
 SUBLEVEL =   12
46
-EXTRAVERSION = testing-22
46
+EXTRAVERSION = -testing-23
47 47
 
48 48
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
49 49
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -393,6 +393,7 @@ int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
393 393
 				int id)
394 394
 {
395 395
 	struct tcp_connection *c;
396
+	struct tcp_connection *tmp;
396 397
 	struct ip_addr ip;
397 398
 	int port;
398 399
 	int fd;
... ...
@@ -470,6 +471,7 @@ get_fd:
470 471
 				goto release_c;
471 472
 			}
472 473
 			DBG("tcp_send, c= %p, n=%d\n", c, n);
474
+			tmp=c;
473 475
 			n=receive_fd(unix_tcp_sock, &c, sizeof(c), &fd);
474 476
 			if (n<=0){
475 477
 				LOG(L_ERR, "BUG: tcp_send: failed to get fd(receive_fd):"
... ...
@@ -477,6 +479,16 @@ get_fd:
477 479
 				n=-1;
478 480
 				goto release_c;
479 481
 			}
482
+			if (c!=tmp){
483
+				LOG(L_CRIT, "BUG: tcp_send: get_fd: got different connection:"
484
+						"  %p (id= %d, refcnt=%d state=%d != "
485
+						"  %p (id= %d, refcnt=%d state=%d (n=%d)\n",
486
+						  c,   c->id,   c->refcnt,   c->state,
487
+						  tmp, tmp->id, tmp->refcnt, tmp->state, n
488
+				   );
489
+				n=-1; /* fail */
490
+				goto release_c;
491
+			}
480 492
 			DBG("tcp_send: after receive_fd: c= %p n=%d fd=%d\n",c, n, fd);
481 493
 		
482 494
 	
... ...
@@ -620,6 +620,15 @@ void tcp_receive_loop(int unix_sock)
620 620
 				con->timeout=get_ticks()+TCP_CHILD_TIMEOUT;
621 621
 				FD_SET(s, &master_set);
622 622
 				if (maxfd<s) maxfd=s;
623
+				if (con==list){
624
+					LOG(L_CRIT, "BUG: tcp_receive_loop: duplicate"
625
+							" connection recevied: %p, id %d, fd %d, refcnt %d"
626
+							" state %d (n=%d)\n", con, con->id, con->fd,
627
+							con->refcnt, con->state, n);
628
+					resp=CONN_ERROR;
629
+					release_tcpconn(con, resp, unix_sock);
630
+					goto skip; /* try to recover */
631
+				}
623 632
 				tcpconn_listadd(list, con, c_next, c_prev);
624 633
 			}
625 634
 skip: