🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #67244

Re: CHECK/TAKETHIS and deadlocks

#67244
From: Curt Welch
Date: Tue, 25 Nov 2003 01:51
101 lines
6263 bytes
"Miquel van Smoorenburg" <miquels@cistron.nl> wrote:
> I have a few doubts about how CHECK/TAKETHIS behaves on
> the client and on the server.
>
> I read draft-ietf-nntpext-streaming-00.txt, which says
> that CHECK and TAKETHIS may be pipelined.
>
> Pipelining is defined in draft-ietf-nntpext-base-20, which says
>
> "If the client uses blocking system calls to send commands, it MUST
>  ensure that the amount of text sent in pipelining does not cause a
>  deadlock between transmission and reception. The amount of text
>  involved will depend on window sizes in the transmission layer, and
>  is typically 4k octets for TCP."
>
> The deadlock situation being, ofcourse, that the server is
> sending a big article using TAKETHIS and not listening on
> the socket, while the client is sending a bunch of CHECK commands
> and also not listening -> deadlock.

The use of the words "client" and "server" get confusing when you talk
about a streaming feed.  It's normally done from "server" to "server", so
which side are you thinking of as the "client"?  Your question would be
more clear if you just talked about the sending side and the receiving side
of the feed.

If you stick with normal nntp conventions, and call the client the side
which starts the connection and sends the commands, then the client is the
one sending articles with TAKETHIS, not the server, so what you say above
seems backwards.  I don't know what the conect of the documentation you
were reading might have chosen to use.

They way a deadlock would happen is if the sending side sent a lot of
checkes and takethis commands without reading the responses.  It would take
a lot, beacuse the flow of respons codes back from the receiving side would
have to fill up the TCP window before it stopped sending, and then at that
point, it would have to stop receiving which would lock up the sending side
once that TCP window was filled.  It's a large loop and both TCP windows
would have to fill up without the sending side reading before it would
deadlock.

> Nothing is said about the server. Is the server allowed to just
> use blocking system calls, and is solely the client responsible
> for making sure no deadlock occurs ?

Yes, it's safe for the receiving side to work that way because it only
sends output in response to a command from the sending side.  There's no
way for the receving side to force a deadlock.  If it writes a response
back to the sending side and locks up because the sending side is not
reading, then it there is nothing it should do.  It could keep reading and
processing commands, but it would have to buffer up an infinite number of
response codes and that's just not resonable.  It has no option to throw
the response codes away because that would break the protocol. It has to
flow control the connection and stop reading.

> I suppose so, since the language is quite similar to the SMTP
> RFCs which are a bit more clear in this regard. Correct ?
> It also makes sense, since the client can send unlimited
> CHECK requests and you can't expect the server to buffer
> an unlimited amount of those.

Yes, exactly.  It doesn't need to be documented in the RFC because there's
only one way it can work.  If it is documented, it's just to help people
understand.

> The question ofcourse is, how do _existing_ implementations
> handle this. Do INN, Diablo, Cyclone, etc all circumvent this
> deadlock in the client, server, or both ?

All NNTP servers send repsonse codes and data back to the client.  If the
client causes the TCP connection to block because the client is not reading
the data from the client, then all servers will stop reading commands from
the client at some point.  The only other option is to buffer up GBs of
unread data somewhere and there's just no reason to do that so they don't.
If the client asks for an article, and the server trys to send it, but the
client doesn't read it, it would be stupid to do anything other than not
send more and not read more requests from the client until the client took
what it already asked for.

> If I wrote a server and client from scratch, how should I handle it ?

Correctly I hope. :)

For a normal news-reading client, the data comming from the server is the
bulk of the transaction.  And most clients will send a single command
(which is always a lot smaller then the TCP window plus output buffer), and
then reads data from the server until it's done.  Even with blocking calls,
it's bascially impossible to deadlock if you send one command and then read
the response.

When you try to pipeline multiple commands using a single-threaded code,
it's easy to deadlock by mistake.  This can happen for a normal client
which is trying to get fancy with pipelining as well as a code trying to
send a streaming feed.

Doing a good job of sending a streaming feed is by far the most complex
NNTP programming there is.  At least I think so.

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                          Webmaster for http://NewsReader.Com/
Technical Details
Message-ID: <20031124205121.603$22@newsreader.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!diablo.voicenet.com!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
References: <bpo0da$f9v$1@news.cistron.nl>

Show Full Headers
Complete Article Headers
Message-ID: <20031124205121.603$22@newsreader.com>
Subject: Re: CHECK/TAKETHIS and deadlocks
Date: Tue, 25 Nov 2003 01:51:21 +0000
From: curt@kcwc.com (Curt Welch)
References: <bpo0da$f9v$1@news.cistron.nl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!diablo.voicenet.com!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com ZsJJoRxgJtt2iV.6HlIMwKLmZFHitY38Fh+kvLiFWhSgOz..2
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,
 ?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5
 %IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-Url: http://CurtWelch.Com/
User-Agent: NewsReader.Com
Lines: 101