classification
Title: Uses of SocketServer.BaseServer.shutdown have a race
Type: behavior
Components: Library (Lib) Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: jyasskin Nosy List: jyasskin, zanella
Priority: Keywords: patch, patch

Created on 2008-03-16 15:15 by jyasskin, last changed 2008-05-07 18:16 by zanella.

Files
File name Uploaded Description Edit Remove
race_free_shutdown.patch jyasskin, 2008-03-16 15:15
Messages
msg63579 (view) Author: Jeffrey Yasskin (jyasskin) Date: 2008-03-16 15:15
With the code as it stands, calls to shutdown that happen before
serve_forever enters its loop will deadlock, and there's no simple way
for the user to avoid this. The attached patch prevents the deadlock and
allows multiple serve_forever..shutdown cycles, but it's pretty
complicated. I could make it a lot simpler by making shutdown permanent:
any later serve_forever calls would return immediately.

A third choice would be to add a .serve_in_thread function that returns
a token that can be used to shut down exactly that loop, instead of
putting .shutdown() on the server. Any opinions?
msg66364 (view) Author: Rafael Zanella (zanella) Date: 2008-05-07 18:16
>With the code as it stands, calls to shutdown that happen before
>serve_forever enters its loop will deadlock, and there's no simple way
>for the user to avoid this. The attached patch prevents the deadlock and
>allows multiple serve_forever..shutdown cycles, but it's pretty
>complicated. I could make it a lot simpler by making shutdown permanent:
>any later serve_forever calls would return immediately.

Never thought of using the SocketServer taht way, wouldn't the person
doing this bunch of shutdown()s and serve_forever()s be better off using
handle_request() on a loop instead ?

>A third choice would be to add a .serve_in_thread function that returns
>a token that can be used to shut down exactly that loop, instead of
>putting .shutdown() on the server. Any opinions?

I don't think I understand this part, what loop do you refer to ?
History
Date User Action Args
2008-05-07 18:16:15zanellasetnosy: + zanella
messages: + msg66364
2008-03-16 22:46:56jyasskinsetkeywords: patch, patch
assignee: jyasskin
2008-03-16 17:20:30jyasskinlinkissue1193577 superseder
2008-03-16 15:15:55jyasskincreate