🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
3 messages
3 total messages Started by Miquel van Smoorenburg Sat, 22 Nov 2003 15:46
CHECK/TAKETHIS and deadlocks
#67226
Author: Miquel van Smoorenburg
Date: Sat, 22 Nov 2003 15:46
36 lines
2713 bytes
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.

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 ?

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.

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 ?

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

Mike.
Re: CHECK/TAKETHIS and deadlocks
#67244
Author: 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/
Re: CHECK/TAKETHIS and deadlocks
#67268
Author: Miquel van Smoorenburg
Date: Wed, 26 Nov 2003 16:30
41 lines
3330 bytes
In article <20031124205121.603$22@newsreader.com>,
Curt Welch <curt@kcwc.com> wrote:
>"Miquel van Smoorenburg" <miquels@cistron.nl> wrote:
>> 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.

Well I was just a bit confused, I guess. I know how the protocol
works - the receiving side of my server is already running and
taking both CHECK/TAKETHIS and IHAVE feeds. I had it running a
full feed for weeks without leaking (yay valgrind!).

It's a pet project I have been doing over the last year. It is an
event-based multi-threaded server with cyclic storage and history.
It's interesting to play around with events and threads. Right now
the NNTP receiver is one thread, the storage stuff is multithreaded.
But I'm still working on the model, I might still change it.

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

I'm about to start on the sending part. There's still a lot
to work out - queueing etc. Thanks a lot for your comments.
Hopefully I'll be able to get it right now!

Mike.
-- 
If I seem short sighted, it is because I stand on the shoulders of midgets.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads