[issue8240] ssl.SSLSocket.write may fail on non-blocking sockets

Cyril report at bugs.python.org
Fri Mar 26 16:30:34 CET 2010


New submission from Cyril <cbay at excellency.fr>:

ssl.SSLSocket.write on non-blocking sockets will fail with:

_ssl.c:1217: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry

on a write retry, if the buffer address has changed between the initial call and the retry (when the initial call returned 0 bytes written, which means you should try again later).

>From OpenSSL docs (http://www.openssl.org/docs/ssl/SSL_CTX_set_mode.html):

SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
Make it possible to retry SSL_write() with changed buffer location (the buffer contents must stay the same). This is not the default to avoid the misconception that non-blocking SSL_write() behaves like non-blocking write().

Attached patch fixes the problem (tested on Python 2.6.5, 2.7 trunk) by calling SSL_CTX_set_mode with SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER. It's a single line patch.

----------
components: Library (Lib)
files: _ssl.c.patch
keywords: patch
messages: 101753
nosy: cbay
severity: normal
status: open
title: ssl.SSLSocket.write may fail on non-blocking sockets
versions: Python 2.6, Python 2.7
Added file: http://bugs.python.org/file16668/_ssl.c.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8240>
_______________________________________


More information about the Python-bugs-list mailing list