Issue #4237 has been updated by Hiroshi NAKAMURA.


Thanks for the explanation. I think r30294 (fix for lib/net/smtp.rb) is good. It solved the original problem, right? Of course, ext/openssl should try to shutdown the connection gracefully to the extent possible though.

And the second part, can you remember some more details of SEGV you got? If the error you got is timeout or something, it could be caused by infinite loop by r30451. Is this what you're saying?
http://www.rubyist.net/~akr/chkbuild/debian/ruby-trunk/log/20110105T190101Z.log.html.gz

As I wrote above, bi-directional SSL close is hard to control (opposite side is not controllable) so calling SSL_shutdown() several times without checking could be enough.

Here's what mod_ssl is doing.

int SSL_smart_shutdown(SSL *ssl)
{       
    int i;
    int rc;
    
    /*
     * Repeat the calls, because SSL_shutdown internally dispatches through a
     * little state machine. Usually only one or two interation should be
     * needed, so we restrict the total number of restrictions in order to
     * avoid process hangs in case the client played bad with the socket
     * connection and OpenSSL cannot recognize it.
     */               
    rc = 0;           
    for (i = 0; i < 4 /* max 2x pending + 2x data = 4 */; i++) {
        if ((rc = SSL_shutdown(ssl)))
            break;
    }
    return rc;
}  

If my guess about the error you got is correct, I'll commit similar changes for SSL_shutdown().
----------------------------------------
Bug #4237: SSL_shutdown should be called until it returns 0
http://redmine.ruby-lang.org/issues/4237

Author: Aaron Patterson
Status: Assigned
Priority: Normal
Assignee: Hiroshi NAKAMURA
Category: 
Target version: 
ruby -v: -


=begin
 The documentation says SSL_shutdown should be called until it returns 0.  I believe this was causing heap corruption that can be demonstrated through the steps listed here:
 
   http://intertwingly.net/blog/2010/12/07/SQLite3-CorruptException-database-disk-image-is-malformed
 
 make sure you use Ruby r30293 or earlier.  I believe r30294 only fixed a symptom is it closes the SSL socket twice (once from the call to `close` and once again during GC).
 
 Please note that Sam sees the problem because postfix is establishing a TLS connection.
=end



-- 
http://redmine.ruby-lang.org