This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pravn
Recipients pravn
Date 2019-02-07.12:30:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549542632.16.0.548779418887.issue35928@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-02-07 12:30:34pravnsetrecipients: + pravn
2019-02-07 12:30:32pravnsetmessageid: <1549542632.16.0.548779418887.issue35928@roundup.psfhosted.org>
2019-02-07 12:30:32pravnlinkissue35928 messages
2019-02-07 12:30:31pravncreate