| 1 | If one thread is unregistering the socket while another is issuing pending operation such as recv or send, this may corrupt the descriptor set in the ioqueue, causing subsequent select() inside pj_ioqueue_poll() to return error. |
| 2 | |
| 3 | Detailed scenario: |
| 4 | - thread A issues pj_ioqueue_recv(), and midway it is interrupted by thread B |
| 5 | - thread B issues pj_ioqueue_unregister(sock) which closes the socket. |
| 6 | - thread A resumes execution, ultimately gaining the key's mutex. But it does not check if the key has been unregistered. It adds the socket handle (which has been closed by thread B) to the read descriptor set. |
| 7 | - subsequent select() will return -1 since it contains invalid handle |
| 8 | |
| 9 | This will cause the ioqueue to stop receiving events. |