Unsolved QTcpSocket cannot cancelled during QAbstractSocket::ConnectingState! BUG??!!
-
Hi,
I'm using Qt 4.8.6 and Qt 5.3.0 with VS2010, Win7. Ob both Qt version the same issue/bug occurs!
I'm using QTcpSocket to connect as client to a running server - no problems. But when the server is down/not running, the QTcpSocket::connectToHost() enters following states:
- QAbstractSocket::HostLookupState
- QAbstractSocket::ConnectingState
(Staying there for awhile...) - QAbstractSocket::UnconnectedState
- Error with QAbstractSocket::NetworkError
If now I start the server again immendiately a client is showed as connected - but it's not my client! I cannot send data to the server. Now when I call QTcpSocket::connectToHost() again the server schows me that the first connection is disconnected and a new one is connected. Now I can send data to the server about that new one!
That's strange or should I say: It's a bug! It seems in background the connecting attempt is running further.
The same behaviour is when after
...
2. QAbstractSocket::ConnectingState
(Staying there for awhile...)
--> Here call QTcpSocket::disconnectFromHost() or abort() or close() or reset()!It seems the connecting attempt cannot be cancelled! This spits me into my reconnect mechanism and I cannot make sure it works correct :-(
Any suggestions?
Thanks a lot
-
Hi,
AFAIK, there's a 30s connection timeout, are you trying to connect again in that delay ?
-
He,
yes. If I'm waiting for 30s and more after error with QAbstractSocket::NetworkError occured and try again it seems to work.
But the problem is:
If the server is coming up earlier, e.g. 10s after I got QAbstractSocket::NetworkError on client side, on server side the background attempt is already connected (wrong one).Strange, that nobody has recognized that issue!
I need a function to cancel the background attempt. I tried also ::closesocket() with a socketdescriptor (socketDescriptor() in error() slot), also WSACleanup(), WSAShutdown(). Nothing helped.
Strange also that after WSAShutdown() the QNetwork module works further. For windows there is qnativesocketengine_win.cpp which using winsock2.
-
Added:
Now when the server is down/not running, the QTcpSocket::connectToHost() enters following states:
- QAbstractSocket::HostLookupState
- QAbstractSocket::ConnectingState
(Staying there for only 3s) - QAbstractSocket::UnconnectedState
- Error with QAbstractSocket::ConnectionRefusedError
Definitely it depends of the OS :-(
Ohh, I have a very very bad feeling...Sometimes in the stateChanged() slot with state = UnconnectedState I have access to a valid socket descriptor with socketDescriptor(). Calling ::closesocket(), shutdown()... nothing helps. The background attempt to connect is still alive.
-
What OSs are you using ?
-
Windows7, 64Bit
-
Can you test with a more recent version of Qt ? e.g 5.5.1 or even 5.6 beta ?