Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.15, 6.0
-
None
-
-
fe6d84d96e67113846801803c3ba1f20b26e123f (qt/qtbase/dev) 1489567b3b80578cb2c4daf33ad774429afeaf4f (qt/qtbase/6.1)
Description
Following QTBUG-82776 it is shown that, sometimes, notifications meant for sockets that are now closed are still left in the queue. This is documented[0] and usually it is not a problem since we will discard the events the next time the event-loop is spun. When the event-loop is not spun Windows could reuse the old socket descriptor for a newly created socket (in the related bug-report I could usually reproduce locally after 10-20 runs).
So, steps:
- Create socket
- Use socket
- Close socket (generates a close notification)
- Create new socket (and it ends up assigned with the socket descriptor from the first socket)
- Spin the event loop to deliver the stale socket notification
- The new socket handles it, some side-effects depending on the notification
- e.g. a close notification will try to read data, if no data is available it will disconnect
A possible way this could be fixed would be to somehow remove the related notifications once the socketnotifier is unregistered, but it's not that easy. PeekMessage only shows the first message of a certain type, that means if there are multiple socketnotifiers then if the first message is not related to the current socketnotifier being unregistered then there's no way to access the rest. Removing and requeuing all of them is likely not an option.
[0] https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsaasyncselect#remarks
Although WSAAsyncSelect immediately disables event message posting for the socket in this instance, it is possible that messages could be waiting in the application message queue. Therefore, the application must be prepared to receive network event messages even after cancellation. Closing a socket with closesocket also cancels WSAAsyncSelect message sending, but the same caveat about messages in the queue still applies.
Attachments
Issue Links
- relates to
-
QTBUG-82776 flaky test tst_QTcpSocket::increaseReadBufferSize(WithoutProxy SSL)
-
- Closed
-
For Gerrit Dashboard: QTBUG-82835 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
354171,7 | QNativeSocketWin: Add a system to ignore sockfds for one loop iteration | dev | qt/qtbase | Status: ABANDONED | 0 | 0 |
354521,3 | QEventDispatcherWin32: suppress old {FD_CLOSE|FD_CONNECT} notifications | dev | qt/qtbase | Status: MERGED | +2 | 0 |
355592,2 | QEventDispatcherWin32: suppress old {FD_CLOSE|FD_CONNECT} notifications | 6.1 | qt/qtbase | Status: MERGED | +2 | 0 |
355593,2 | QEventDispatcherWin32: suppress old {FD_CLOSE|FD_CONNECT} notifications | 6.2 | qt/qtbase | Status: MERGED | +2 | 0 |