I am seeing this in a process that has a number of threads writing to a
set of SSL servers. The write to each ssl context is mutex protected, so
writes are serialized. 

Problem seems to be triggered by a server closing a connection (at the
tcp level) unexpectedly. One thread "discovers" this when it gets an
EPIPE, but other threads will still try to write to the ssl context. I
would have hoped that subsequent writes would raise an error to the
effect of "connection has been closed, this ctx is no longer valid", but
that doesn't seem to happen.

The OpenSSL docs make me think that the underlying SSL_write call is
being misused if this error is seen.

With OpenSSL::debug=true:

% /usr/local/bin/ruby1.8.x ./bin/bcms 13130011
OSSL_DEBUG: IS NOW ON!
cbid 03db8bb4f8d7f088 chnd nil/usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `syswrite': Broken pipe (Errno::EPIPE)
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `do_write'
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:192:in `write'
        from ./bin/../lib/bycast/neighbour/connection.rb:502:in `write'
        from /usr/local/lib/ruby/1.8/thread.rb:135:in `synchronize'
        from ./bin/../lib/bycast/neighbour/connection.rb:496:in `write'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:128:in `send'
        from ./bin/../lib/bycast/ldri.rb:89:in `object_info'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:142:in `endpoint'
         ... 6 levels...
        from ./bin/bcms:172:in `times'
        from ./bin/bcms:172:in `initialize'
        from ./bin/bcms:270:in `new'
        from ./bin/bcms:270

/usr/local/lib/ruby/1.8/openssl/buffering.rb:178: warning: error on stack: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
/usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `syswrite': SSL_write:: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry (OpenSSL::SSL::SSLError)
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `do_write'
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:192:in `write'
        from ./bin/../lib/bycast/neighbour/connection.rb:502:in `write'
        from /usr/local/lib/ruby/1.8/thread.rb:135:in `synchronize'
        from ./bin/../lib/bycast/neighbour/connection.rb:496:in `write'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:128:in `send'
        from ./bin/../lib/bycast/ldri.rb:89:in `object_info'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:142:in `endpoint'
         ... 6 levels...
        from ./bin/bcms:172:in `times'
        from ./bin/bcms:172:in `initialize'
        from ./bin/bcms:270:in `new'
        from ./bin/bcms:270


Without OpenSSL::debug=true:

% ruby1.8.x -v
ruby 1.8.5 (2007-01-27 patchlevel 17) [i686-linux]

% /usr/local/bin/ruby1.8.x ./bin/bcms 13130011
/usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `syswrite': Broken pipe (Errno::EPIPE)
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `do_write'
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:192:in `write'
        from ./bin/../lib/bycast/neighbour/connection.rb:502:in `write'
        from /usr/local/lib/ruby/1.8/thread.rb:135:in `synchronize'
        from ./bin/../lib/bycast/neighbour/connection.rb:496:in `write'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:128:in `send'
        from ./bin/../lib/bycast/ldri.rb:89:in `object_info'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:142:in `endpoint'
         ... 6 levels...
        from ./bin/bcms:172:in `times'
        from ./bin/bcms:172:in `initialize'
        from ./bin/bcms:270:in `new'
        from ./bin/bcms:270

/usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `syswrite': SSL_write:: bad write retry (OpenSSL::SSL::SSLError)
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:178:in `do_write'
        from /usr/local/lib/ruby/1.8/openssl/buffering.rb:192:in `write'
        from ./bin/../lib/bycast/neighbour/connection.rb:502:in `write'
        from /usr/local/lib/ruby/1.8/thread.rb:135:in `synchronize'
        from ./bin/../lib/bycast/neighbour/connection.rb:496:in `write'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:128:in `send'
        from ./bin/../lib/bycast/ldri.rb:89:in `object_info'
        from ./bin/../lib/bycast/neighbour/endpoint.rb:142:in `endpoint'
         ... 6 levels...
        from ./bin/bcms:172:in `times'
        from ./bin/bcms:172:in `initialize'
        from ./bin/bcms:270:in `new'
        from ./bin/bcms:270