From: Eric Wong <normalperson@yhbt.net>
To: kgio@librelist.org
Subject: Re: handling Timeout.timeout with sockets
Date: Thu, 3 May 2012 07:10:01 +0000 [thread overview]
Message-ID: <20120503071000.GA14041@dcvr.yhbt.net> (raw)
In-Reply-To: CAMKTR6cBqu5Zyprzc-2HQxz+_hckwT08+_phctAGYe83PUREZA@mail.gmail.com
Mike Perham <mperham@gmail.com> wrote:
> I've noticed that my code cannot rescue the Timeout::Error that is
> raised and I expect that is by design.
Yes, it's by design. Reading timeout.rb (and its
"git log -p --full-diff" history) is enlightening, btw. You'll also
get better performance if you explicitly specify a class for timeout
to raise (ref: https://bugs.ruby-lang.org/issues/5765)
> However I'm wondering how my network client can recover from that
> timeout? Presumably there is now data to be read on the socket which,
> due to the timeout, has not been read, meaning my protocol state
> machine is now out of sync, thus leading to the crash.
>
> Should I drain the socket somehow before each operation? What is the
> best way to do this?
The easiest way is to open a new socket.
The other way is to _completely_ parse the old response (that timed out)
before reusing the socket.
Do _not_ rely on IO#nread in the io/wait module for this, it's
inherently racy: bytes may arrive after you call IO#nread. Unless the
protocol changed recently, for memcached (and nearly everything
implemented on top of TCP), you must completely parse the response the
server gives you.
prev parent reply other threads:[~2012-05-03 7:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAMKTR6d=LaskRS=WQfveK7ep6FuPohK0C5cAEqZj4cxLVBzvqQ@mail.gmail.com>
2012-05-03 4:55 ` handling Timeout.timeout with sockets Mike Perham
2012-05-03 7:10 ` Eric Wong [this message]
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
List information: https://yhbt.net/kgio/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120503071000.GA14041@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=kgio@librelist.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.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/kgio.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).