kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Mike Perham <mperham@gmail.com>
To: kgio@librelist.org
Subject: handling Timeout.timeout with sockets
Date: Wed, 2 May 2012 21:55:23 -0700	[thread overview]
Message-ID: <CAMKTR6cBqu5Zyprzc-2HQxz+_hckwT08+_phctAGYe83PUREZA@mail.gmail.com> (raw)
In-Reply-To: CAMKTR6d=LaskRS=WQfveK7ep6FuPohK0C5cAEqZj4cxLVBzvqQ@mail.gmail.com

Users of dalli are seeing a very rare issue
(https://github.com/mperham/dalli/issues/146) where a Timeout will
cause the client to crash.  They noticed this reproduces the bug:

require 'timeout'
require 'dalli'

Dalli.logger.level = Logger::DEBUG
client = Dalli::Client.new(["127.0.0.1:11211"], :socket_timeout => 0.01)

begin
 Timeout.timeout 0.01 do
   while true
     client.set("test_123", {:test => "123"})
   end
 end
rescue Timeout::Error => e
 puts [e.class.name, e.message]
 puts e.backtrace.join("\n")
end

p client.get("test_123")

I've noticed that my code cannot rescue the Timeout::Error that is
raised and I expect that is by design.  The block should be timed out
after the interval and code within the block should not be able to
rescue and stop that.

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?

mike

       reply	other threads:[~2012-05-03  4:55 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 ` Mike Perham [this message]
2012-05-03  7:10   ` handling Timeout.timeout with sockets Eric Wong

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=CAMKTR6cBqu5Zyprzc-2HQxz+_hckwT08+_phctAGYe83PUREZA@mail.gmail.com \
    --to=mperham@gmail.com \
    --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).