[New-bugs-announce] [issue23804] SSLSocket.recv(0) receives up to 1024 bytes

Martin Panter report at bugs.python.org
Sun Mar 29 12:30:23 CEST 2015

New submission from Martin Panter:

The documentation claims that SSL socket objects provide some of the same methods as plain socket objects, including recv(), and that the “bufsize” parameter specifies the maximum amount of data to be received. With ordinary sockets, socket.recv(0) always seems to return zero bytes (b""), as expected. But not so with SSL sockets:

>>> import socket, ssl
>>> s = ssl.wrap_socket(socket.create_connection(("localhost", 631)))
>>> s.sendall(b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n")
>>> len(s.recv(0))
>>> len(s.recv(0))

The call will hang or raise SSLWantReadError when no data is actually available. Looking at the code, the value of zero seems to be used as a placeholder for a default of 1024 in SSLObject.read(). Either the SSL module should be fixed to return no bytes (my preference), or the documentation needs to warn that the recv(0) is not supported, or does not work the same as for plain sockets. SSLSocket.read() might also be affected.

components: Library (Lib)
messages: 239483
nosy: vadmium
priority: normal
severity: normal
status: open
title: SSLSocket.recv(0) receives up to 1024 bytes
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list