Search code examples
socketstornadoepollevent-loopkqueue

Do I need to unregister fd from epoll/kqueue when closing socket?


Is it true that if I close a socket its fd is auto purged from epoll and/or kqueue?
If so, does it means there is no need to manually unregister the fd when closing fd?

Actually I'm using Tornado, any advice on that would also be appreciated.


Solution

  • In Tornado, you must call IOLoop.remove_handler before closing the socket. Epoll and kqueue will internally discover automatically that the socket has been closed, but the IOLoop itself still has some state (a mapping from file descriptors to handler functions) that needs to be cleaned up.