Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #2056 (new defect)

Opened 13 years ago

EpollSelector: Problems with unregistering keys while iterating over the selected set

Reported by: gavin Assigned to: community
Priority: normal Milestone: 1.0
Component: Tango Version: 0.99.9 Kai
Keywords: epoll, selector Cc:

Description

The selected set iterator iterates over the _events array, which contains pointers to SelectionKey? structs stored in the _keys associative array, passing them through to the opApply delegate. If, during iteration of the selected set, a key is unregistered, then it will be removed from the _keys array. The removal of a key actually deletes it, thus potentially resulting in the situation where the _events array contains a pointer to an invalid memory location (the recently deleted SelectionKey?).

Suggested fix: The _keys array could store pointers to SelectionKey? structs, rather than the structs themselves. The actual structs can then be newed in the call to register(). To avoid continually newing new structs, upon removing a key from the _keys array, its pointer could be added to an internal list of 'free keys', and pointers from this list used in future register() calls, rather than newing every time.

Sorry, I don't have time right now to fully implement and test this idea, but should be able to get round to it at some point.