New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
socket makefile read-write discards received data #80109
Comments
|
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)) 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: Python 3.6.6: |
|
Looking over the changelog, my guess (untested) is this is caused by commit d6a283b for bpo-25862. That change looks like it drops the internal TextIOWrapper decoding buffer for each successful write. I don't have the right version of Python to test with, but I expect this to also be broken without using a socket: >>> f = TextIOWrapper(BufferedRWPair(BytesIO(b"Hello\nYou\n"), BytesIO()))
>>> f.readline()
'Hello\n'
>>> f.write(_)
6
>>> f.readline() # Does this now return EOF?
'You\n' |
>>> f = TextIOWrapper(BufferedRWPair(BytesIO(b"Hello\nYou\n"), BytesIO()))
>>> f.readline()
'Hello\n'
>>> f.write(_)
6
>>> f.readline() # Returns empty string
'' |
|
Recreatable on master as well, also Martin your suspicion seems correct, reverting 23db935 fixes it. |
pravn mannequin commentedFeb 7, 2019
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: