Patch: avoid infinite loop on PRPoll call in camel tcp stream ssl if connection times out.



	Hi,

	This patch fixes the problem that happened when a connection using tcp
stream ssl (the nss based one) got continuous timeouts and never
finished the loop. This caused effective hangs on getting network down,
but without explicit disconnection from network.

Changelog entry:
    * libtinymail-camel/camel-lite/camel/camel-tcp-stream-ssl.c: on calls to
      PR_Poll with a timeout, we didn't take into account properly the case
      we reached the timeout, and it could be creating infinite loops if
      connection failed but didn't die.

-- 
José Dapena Paz <jdapena igalia com>
Igalia
diff --git a/ChangeLog b/ChangeLog
index f7d66c5..3fed932 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-18  Jose Dapena Paz  <jdapena igalia com>
+
+	* libtinymail-camel/camel-lite/camel/camel-tcp-stream-ssl.c: on calls to
+	PR_Poll with a timeout, we didn't take into account properly the case
+	we reached the timeout, and it could be creating infinite loops if
+	connection failed but didn't die.
+
 2009-08-12  Sergio Villar Senin  <svillar igalia com>
 
 	* libtinymail/tny-fs-stream-cache.c (get_available_size)
diff --git a/libtinymail-camel/camel-lite/camel/camel-tcp-stream-ssl.c b/libtinymail-camel/camel-lite/camel/camel-tcp-stream-ssl.c
index f08e673..0de5290 100644
--- a/libtinymail-camel/camel-lite/camel/camel-tcp-stream-ssl.c
+++ b/libtinymail-camel/camel-lite/camel/camel-tcp-stream-ssl.c
@@ -517,6 +517,7 @@ stream_read_nb (CamelTcpStream *stream, char *buffer, size_t n)
 #else
 			errno = EIO;
 #endif
+			goto failed;
 		} else {
 			 do {
 				nread = -1;
@@ -532,7 +533,7 @@ stream_read_nb (CamelTcpStream *stream, char *buffer, size_t n)
 	} while (0 && (nread == -1 && (PR_GetError () == PR_PENDING_INTERRUPT_ERROR ||
 				 PR_GetError () == PR_IO_PENDING_ERROR ||
 				 PR_GetError () == PR_WOULD_BLOCK_ERROR)));
-
+ failed:
 	/* restore O_NONBLOCK options */
 	sockopts.option = PR_SockOpt_Nonblocking;
 	sockopts.value.non_blocking = nonblock;
@@ -587,6 +588,7 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
 #else
 				errno = EIO;
 #endif
+				goto failed1;
 			} else {
 				do {
 					nread = -1;
@@ -602,6 +604,7 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
 					 PR_GetError () == PR_IO_PENDING_ERROR ||
 					 PR_GetError () == PR_WOULD_BLOCK_ERROR));
 
+	failed1:
 		/* restore O_NONBLOCK options */
 		error = errno;
 		sockopts.option = PR_SockOpt_Nonblocking;
@@ -645,10 +648,10 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
 #else
 				errno = EIO;
 #endif
-				goto failed;
+				goto failed2;
 			} else if (pollfds[1].out_flags == PR_POLL_READ) {
 				errno = EINTR;
-				goto failed;
+				goto failed2;
 			} else {
 				do {
 					nread = -1;
@@ -665,7 +668,7 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
 					 PR_GetError () == PR_WOULD_BLOCK_ERROR));
 
 		/* restore O_NONBLOCK options */
-	failed:
+	failed2:
 		error = errno;
 		sockopts.option = PR_SockOpt_Nonblocking;
 		sockopts.value.non_blocking = nonblock;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]