Skip to content

bpo-41093: TCPServer's serve_forever() shuts down immediately when calling shutdown() #21094

Open
tontinton wants to merge 4 commits into
python:mainfrom
tontinton:fix-issue-41093
Open

bpo-41093: TCPServer's serve_forever() shuts down immediately when calling shutdown() #21094
tontinton wants to merge 4 commits into
python:mainfrom
tontinton:fix-issue-41093

Conversation

@tontinton
Copy link
Copy Markdown
Contributor

@tontinton tontinton commented Jun 23, 2020

@tontinton tontinton changed the title bpo-41093: BaseServer's server_forever() shutdown immediately when calling shutdown() bpo-41093: BaseServer's serve_forever() shutdown immediately when calling shutdown() Jun 23, 2020
@tontinton tontinton force-pushed the fix-issue-41093 branch 2 times, most recently from 64facaf to e4987db Compare June 23, 2020 20:27
@tontinton tontinton changed the title bpo-41093: BaseServer's serve_forever() shutdown immediately when calling shutdown() bpo-41093: BaseServer's serve_forever() shuts down immediately when calling shutdown() Jun 23, 2020
@tontinton tontinton force-pushed the fix-issue-41093 branch 3 times, most recently from 285bf33 to 49bcf7e Compare June 24, 2020 09:11
@tontinton tontinton changed the title bpo-41093: BaseServer's serve_forever() shuts down immediately when calling shutdown() bpo-41093: TCPServer's serve_forever() shuts down immediately when calling shutdown() Jun 24, 2020
@tontinton tontinton changed the title bpo-41093: TCPServer's serve_forever() shuts down immediately when calling shutdown() bpo-41093: TCPServer's serve_forever() shuts down immediately when calling shutdown() Jun 26, 2020
@tontinton
Copy link
Copy Markdown
Contributor Author

poke

Copy link
Copy Markdown
Contributor

@dorosch dorosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for your commits and welcome to the cpython.
Your changes look good. Perhaps you would describe these changes in the documentation before other participants look at your code there. You can added docs for your changes in Doc/library/sockerserver.rst. And in my opinion you can added some tests for your changes in Lib/test/test_sockerserver.py.

Comment thread Lib/socketserver.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method mark as overridden but if we override it we need to know that need to call self.server_close(). This is not obvious in my opinion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, from now server_shutdown will only shutdown the socket without closing it.

Comment thread Lib/socketserver.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, don't need to remove this comment because the proposal has not yet been resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the comment again, but I do think that by implementing the server_shutdown() function this is resolved

Comment thread Lib/socketserver.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the comment style of this file. Comments are written before the comment line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread Lib/socketserver.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, it is worth leaving this method as pass. How this is done with the server_activate method since this is an unobvious behavior of the method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@tontinton tontinton force-pushed the fix-issue-41093 branch 5 times, most recently from a90e6b5 to 5c5fb9c Compare July 4, 2020 20:28
@tontinton
Copy link
Copy Markdown
Contributor Author

Thanks so much for your commits and welcome to the cpython.
Your changes look good. Perhaps you would describe these changes in the documentation before other participants look at your code there. You can added docs for your changes in Doc/library/sockerserver.rst. And in my opinion you can added some tests for your changes in Lib/test/test_sockerserver.py.

After adding a test I realized that this fixes the issue only on windows and linux, mac os works the same, nothing changes

@furkanonder
Copy link
Copy Markdown
Contributor

@tontinton Could you resolve the conflicts?

tontinton added 3 commits May 10, 2023 19:10
server_shutdown() is called on BaseServer's shutdown method to make
server_forever() return immediately on shutdown not waiting for select()
to timeout or return on EVENT_READ.
Fixed issue `41093` as now every server inheriting TCPServer will
shutdown immediately after calling shutdown().

Note: UDPServer doesn't call shutdown() on it's server socket as there
is no need.
The test creates a TCPServer and calls server_forever on it with a high
poll interval of 30 seconds, then calls shutdown on it and validates that it took less
than a second.
@tontinton
Copy link
Copy Markdown
Contributor Author

@tontinton Could you resolve the conflicts?

@furkanonder fixed.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants