STINNER Victor added the comment:

If I understood correctly, to fix this race condition, there are two main 
constraints:

(A) We must call handlers of dispatcher registered before calling 
select()/poll(): dispatchers can be closed and their file descriptor can be 
reused while we execute other dispatchers

(B) Don't call closed dispatcher

--

For (A), I only see one option: copy somehow the map, for example using: ready 
= [(map[fd], flags) for fd, flags in r]

--

For (B), it's more tricky.

The bpo-30985 proposes to start using the closing: I'm not sure that it's 
doable in a stable version like 3.6, or worse in 2.7, since existing code may 
use closing differently.
http://bugs.python.org/issue30985#msg299154

I'm also concerned about subclassing: if a subclass overrides *completely* 
close(), we would fail to detect that the dispatcher was closed. Maybe this 
corner doesn't occur in the wild?

I see a different approach: while iterating on "ready" objects, check again if 
map.get(fd) still is the expected dispatcher. If the file descriptor is no more 
registered in map: it was closed. If we get a new dispatcher: not only the 
previous dispatcher was closed, but a new dispatcher also got the same file 
descriptor and was registered in the map.

Do you think that this approach would work? Would it be safer in term of 
backward compatibility?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30931>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to