From: Abhijit Menon-Sen <ams@wiw.org>
To: linux-kernel@vger.kernel.org
Subject: how is recv(..., MSG_PEEK) racy?
Date: Tue, 23 Sep 2003 12:15:45 +0530 [thread overview]
Message-ID: <20030923121545.D700@lustre.dyn.wiw.org> (raw)
(I'm reposting to linux-kernel because I got no response on netdev.)
I'm trying to understand a fetchmail problem that causes large downloads
from IMAP servers to fail randomly. For some reason, fetchmail uses the
following bizarre code inside a loop to read data from the server:
if ((n = recv(sock, bp, len, MSG_PEEK)) <= 0)
return (-1);
if ((newline = memchr(bp, '\n', n)) != NULL)
n = newline - bp + 1;
if ((n = read(sock, bp, n)) == -1)
return (-1);
The problem occurs (at an unpredictable time, but very often, and with a
greater probability with a larger attachment) when the recv() returns 0,
although tcpdump doesn't show the server closing the connection, or any
other unusual behaviour.
Are there any circumstances other than the connection being closed where
recv(..., MSG_PEEK) can return 0? (Stevens/SUSv3 don't mention any.)
I found the following (paraphrased) comment in net/ipv4/tcp.c:
if ((flags & MSG_PEEK) && peek_seq != tp->copied_seq) {
printk(KERN_DEBUG "TCP(%s:%d): Application bug, race in MSG_PEEK.\n",
current->comm, current->pid);
While fetchmail doesn't seem to be triggering that printk(), I'm curious
about what the race condition is. Google found a post by DaveM saying it
has something to do with URG data, but without any further details. I'd
appreciate any explanation of the problem(s).
Thank you.
-- ams
next reply other threads:[~2003-09-23 6:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-23 6:45 Abhijit Menon-Sen [this message]
2003-09-23 7:33 ` David S. Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030923121545.D700@lustre.dyn.wiw.org \
--to=ams@wiw.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®