[issue35928] socket makefile read-write discards received data

2019-02-10 Thread Palle Ravn


Palle Ravn  added the comment:

>>> f = TextIOWrapper(BufferedRWPair(BytesIO(b"Hello\nYou\n"), BytesIO()))
>>> f.readline()
'Hello\n'
>>> f.write(_)
6
>>> f.readline()  # Returns empty string
''

--

___
Python tracker 
<https://bugs.python.org/issue35928>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35928] socket makefile read-write discards received data

2019-02-07 Thread Palle Ravn


New submission from Palle Ravn :

Using socket.makefile in read-write mode had a bug introduced between version 
3.6.6 and 3.6.7. The same bug is present in version 3.7.x.

The below code example will behave very differently between 3.6.6 and 3.6.7. 
It's based on the echo-server example from the docs.

import socket

HOST = '127.0.0.1'
PORT = 0

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))

print(f'Waiting for connection on port {s.getsockname()[1]}')
s.listen(1)

conn, addr = s.accept()
print(f'Connected by {addr}')

with conn:
f = conn.makefile(mode='rw')

while True:
m = f.readline()
print(f'msg: {m!r}')

if not m:
exit(0)

f.write(m)
f.flush()


Python 3.6.7:
Sending the string "Hello\nYou\n" will only print "Hello\n" and also only 
return "Hello\n" to the client.
Removing the lines with f.write(m) and f.flush() and both "Hello\n" and "You\n" 
will be returned to the client.
It's like the call to f.write() somehow empties the read buffer.

Python 3.6.6:
Sending "Hello\nYou\n" will return "Hello\n" and "You\n" to the client without 
any modifications to the above code.

--
components: IO
messages: 335017
nosy: pravn
priority: normal
severity: normal
status: open
title: socket makefile read-write discards received data
type: behavior
versions: Python 3.6, Python 3.7

___
Python tracker 
<https://bugs.python.org/issue35928>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com