Apply error handling patch from Matthew Willson
commit5939e0855ff1e84021cbfd4a72a6b6d9827a25df
authorEric Wong <normalperson@yhbt.net>
Wed, 3 Sep 2008 22:12:36 +0000 (3 15:12 -0700)
committerEric Wong <normalperson@yhbt.net>
Tue, 9 Sep 2008 01:59:21 +0000 (8 18:59 -0700)
treedbb3846ccd1f6d936e580a82ee26011a13c9d230
parentb0b702171b01e391d9fe29eb4374d971c2f5bc83
Apply error handling patch from Matthew Willson

Ref: http://rubyforge.org/tracker/index.php?func=detail&aid=15987&group_id=1513&atid=5923
> Submitted By: Matthew Willson
> Summary: Errors on subsequent requests after client times out
>   waiting for a response from tracker on a previous request (it
>   leaves the socket open)
>
> Detailed description
>
> The summary says it all really.
>
> Once in a while, the tracker will time out responding to, say, a
> create_open or a create_close command, raising one of these:
>
> MogileFS::UnreadableSocketError: 146.101.142.132:7001 never became readable
>        from /usr/lib/ruby/gems/1.8/gems/mogilefs-client-1.2.1/lib/mogilefs/backend.rb:158:in `readable?'
>        from /usr/lib/ruby/gems/1.8/gems/mogilefs-client-1.2.1/lib/mogilefs/backend.rb:122:in `do_request'
>        from /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
>        from /usr/lib/ruby/gems/1.8/gems/mogilefs-client-1.2.1/lib/mogilefs/backend.rb:108:in `do_request'
>        from /usr/lib/ruby/gems/1.8/gems/mogilefs-client-1.2.1/lib/mogilefs/backend.rb:16:in `create_open'
>        from /usr/lib/ruby/gems/1.8/gems/mogilefs-client-1.2.1/lib/mogilefs/mogilefs.rb:108:in `new_file'
>        from /usr/lib/ruby/gems/1.8/gems/mogilefs-client-1.2.1/lib/mogilefs/mogilefs.rb:163:in `store_content'
>        from ./script/../config/../config/../app/models/mogile_backed.rb:59:in `store_in_mogile'
>        from ./script/../config/../config/../app/models/image.rb:139:in `data'
>        from ./script/../config/../config/../app/models/mogile_backed.rb:59:in `store_in_mogile'
>        from (irb):15
>        from (irb):15
>
> The problem is that, if you code catches this error and carries
> on using the same client object for a subsequent request, the
> 'OK' response which we timed out waiting for, will eventually
> arrive, and sit in the socket's read buffer. It will then be
> read and treated as the response to some unconnected subsequent
> command, resulting in a variety of seemingly intermittent and
> confusing errors.
>
> I've attached a patch for this against 1.2.1, which simply
> closes the socket whenever it times out waiting for a reponse.
> The next request will then open a new socket as required.
>
> Also included a quick fix/improvement to error reporting in one
> case, which helped me to  track the problem down.
lib/mogilefs/backend.rb
lib/mogilefs/mogilefs.rb