Improved workaround for stray events after handlers are deleted.

This really should never happen.  I traced through the code, and the only
way I can see it happening is if epoll returns an event after that fd is
unregistered... which is not supposed to be possible.  But maybe a kernel
bug could make it possible, or I've missed a case.

Anyway, when this happened and the respective handler had *already* been
removed and epoll had correctly already had the fd removed, we'd get an
uncaught exception when trying to remove it from epoll upon noticing that
there is no handler.

This changes the removal to use remove_handler() instead, which knows how to
catch the exception.  It also breaks out the KeyError check, just in case a
handler ever accidentally leaks an irrelevant KeyError that would cause
confusion.  (That doesn't seem to have actually happened so far.)

Also added a contrived unit test that at least fails with the old code and
passes with the new code.


Change-Id: Ic440d0251891e976eb0737d04a89dfed1b2678f6
1 file changed