dealing with client disconnects with TeeInput
normalperson at yhbt.net
Thu Nov 12 05:04:49 EST 2009
Foreword: this probably doesn't affect nginx+Unicorn users, which is the
recommended configuration for the vast majority of sites. It probably
affects Rainbows! users using Thread* or Revactor the most, and probably
some Unicorn users serving Intranet clients directly.
When clients are uploading large files, there's always a good
possibility of them disconnecting before the upload ends. For other web
app servers it's not much of a problem: they read the entire upload
before attempting to process things; so the app never sees a prematurely
However Rainbows! and Unicorn have the TeeInput class which allows
real-time processing of uploads as they occur. Now, we _want_ the
exception to be thrown and application to stop processing the dead
client request immediately. I've made changes in unicorn.git and
rainbows.git to ensure no EOFError exceptions from the socket are
silenced, not just ones from reading trailers.
However, this means (many more) socket errors will be seen within the
application and any global exception trappers they use will see them as
well. For Rails (and possibly other frameworks), this can mean very
messy log files with large backtraces.
So, would making a Unicorn::Disconnect < EOFError exception class and
raising it with a short/empty backtrace on EOFErrors be the best way to
go? That way those global exception trappers can distinguish between
EOFError exceptions raised by Unicorn/Rainbows! itself and other code
that Unicorn/Rainbows does not care about, and log appropriately...
The other option we have is catch/throw. We can avoid worrying about
the stack trace entirely, and middlewares that opt-in can still capture
and log the disconnect if they want to. More maintenance overhead for
Rainbows! with all its concurrency models, but this is a situation
where I think catch/throw is appropriate for given the current
middleware/application stacks these days.
Thanks for reading.
More information about the mongrel-unicorn