From owner-freebsd-bugs@FreeBSD.ORG Mon Aug 1 12:10:06 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 65BFB106564A for ; Mon, 1 Aug 2011 12:10:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 29D438FC14 for ; Mon, 1 Aug 2011 12:10:06 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p71CA6hg074538 for ; Mon, 1 Aug 2011 12:10:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p71CA6kx074537; Mon, 1 Aug 2011 12:10:06 GMT (envelope-from gnats) Resent-Date: Mon, 1 Aug 2011 12:10:06 GMT Resent-Message-Id: <201108011210.p71CA6kx074537@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mathieu Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8CAC01065672 for ; Mon, 1 Aug 2011 12:05:18 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 7D1838FC20 for ; Mon, 1 Aug 2011 12:05:18 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p71C5Iaq092636 for ; Mon, 1 Aug 2011 12:05:18 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p71C5Ieo092633; Mon, 1 Aug 2011 12:05:18 GMT (envelope-from nobody) Message-Id: <201108011205.p71C5Ieo092633@red.freebsd.org> Date: Mon, 1 Aug 2011 12:05:18 GMT From: Mathieu To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/159352: accidental busy-waiting loop in fetch(3) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2011 12:10:06 -0000 >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: