Skip to content

socketserver's TCPServer documentation only presents case of single request per connection #112020

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

Closed
talcs opened this issue Nov 13, 2023 · 1 comment · Fixed by #129741
Closed
Labels
docs Documentation in the Doc dir

Comments

@talcs
Copy link
Contributor

talcs commented Nov 13, 2023

Documentation

The TCPServer examples here suggest that the BaseRequestHandler.handle method should call self.request.recv just once, and return, which closes the socket immediately, forcing the client to create a new socket and reconnect for every single request.

I think there should be at least one example where the handle method keeps running until the client hangs, which can be indicated when recv's returned value has a length of 0, which by the way, should be covered in the socket.recv documentation. The meaning of 0 as a returned value of socket.recv is covered in the C API docs.

Sample code that allows multiple requests using the same connection can be seen here.

Linked PRs

@talcs talcs added the docs Documentation in the Doc dir label Nov 13, 2023
@talcs talcs changed the title socketserver's TCPServer documentation is partial and might be misleading socketserver's TCPServer documentation is partial and could be misleading Nov 13, 2023
@talcs talcs changed the title socketserver's TCPServer documentation is partial and could be misleading socketserver's TCPServer documentation only presents case of single request per connection Nov 13, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 20, 2024
serhiy-storchaka pushed a commit that referenced this issue Feb 20, 2024
serhiy-storchaka pushed a commit that referenced this issue Feb 20, 2024
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
@davetapley
Copy link

@talcs wow thank you so much for this, it just led to a fix for a longstanding and intermittent bug I had 🙏🏻 🙏🏻 🙏🏻

Super lucky I just happened to be skimming socket docs for an unrelated project and noticed it 😂

diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this issue Jan 22, 2025
gpshead added a commit to gpshead/cpython that referenced this issue Feb 6, 2025
Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
gpshead added a commit that referenced this issue Feb 6, 2025
gh-112020: Rework socketserver examples to be correct.

Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 6, 2025
…-129741)

pythongh-112020: Rework socketserver examples to be correct.

Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
(cherry picked from commit 78377c7)

Co-authored-by: Gregory P. Smith <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 6, 2025
…-129741)

pythongh-112020: Rework socketserver examples to be correct.

Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
(cherry picked from commit 78377c7)

Co-authored-by: Gregory P. Smith <[email protected]>
gpshead added a commit that referenced this issue Feb 6, 2025
…) (#129743)

gh-112020: Rework socketserver examples to be correct.

Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
(cherry picked from commit 78377c7)

Co-authored-by: Gregory P. Smith <[email protected]>
gpshead added a commit that referenced this issue Feb 6, 2025
…) (#129744)

gh-112020: Rework socketserver examples to be correct.

Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
(cherry picked from commit 78377c7)

Co-authored-by: Gregory P. Smith <[email protected]>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Feb 7, 2025
…29741)

pythongh-112020: Rework socketserver examples to be correct.

Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
cmaloney pushed a commit to cmaloney/cpython that referenced this issue Feb 8, 2025
…29741)

pythongh-112020: Rework socketserver examples to be correct.

Outdated code updated, the BaseRequestHandler example is now much more
illustrative instead of the bad idea of a single recv() call for TCP.

tested, they now work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants