Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Aug 2011 12:05:18 GMT
From:      Mathieu <sigsys@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/159352: accidental busy-waiting loop in fetch(3)
Message-ID:  <201108011205.p71C5Ieo092633@red.freebsd.org>
Resent-Message-ID: <201108011210.p71CA6kx074537@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         159352
>Category:       bin
>Synopsis:       accidental busy-waiting loop in fetch(3)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 01 12:10:05 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Mathieu
>Release:        8.2-STABLE
>Organization:
>Environment:
8.2-STABLE FreeBSD 8.2-STABLE #0 r223938M
>Description:
Sometimes, fetch(1) will use 100% CPU time while downloading.  There's a loop that will retry I/O syscalls that returned EAGAIN immediately without blocking due to a small bug.

>How-To-Repeat:
Probably only noticeable on slow links.

>Fix:
Index: common.c
===================================================================
--- common.c	(revision 223938)
+++ common.c	(working copy)
@@ -429,12 +429,6 @@
 	ssize_t rlen, total;
 	int r;
 
-	if (fetchTimeout) {
-		FD_ZERO(&readfds);
-		gettimeofday(&timeout, NULL);
-		timeout.tv_sec += fetchTimeout;
-	}
-
 	total = 0;
 	while (len > 0) {
 		/*
@@ -474,6 +468,11 @@
 			return (-1);
 		}
 		// assert(rlen == FETCH_READ_WAIT);
+		if (fetchTimeout) {
+			FD_ZERO(&readfds);
+			gettimeofday(&timeout, NULL);
+			timeout.tv_sec += fetchTimeout;
+		}
 		while (fetchTimeout && !FD_ISSET(conn->sd, &readfds)) {
 			FD_SET(conn->sd, &readfds);
 			gettimeofday(&now, NULL);
@@ -576,14 +575,13 @@
 	ssize_t wlen, total;
 	int r;
 
-	if (fetchTimeout) {
-		FD_ZERO(&writefds);
-		gettimeofday(&timeout, NULL);
-		timeout.tv_sec += fetchTimeout;
-	}
-
 	total = 0;
 	while (iovcnt > 0) {
+		if (fetchTimeout) {
+			FD_ZERO(&writefds);
+			gettimeofday(&timeout, NULL);
+			timeout.tv_sec += fetchTimeout;
+		}
 		while (fetchTimeout && !FD_ISSET(conn->sd, &writefds)) {
 			FD_SET(conn->sd, &writefds);
 			gettimeofday(&now, NULL);


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108011205.p71C5Ieo092633>