PDA

View Full Version : QNetworkAccessManager finished() isn't emitted after the 2nd request when SSL error



Dmitro25
18th April 2020, 14:02
Hi!
I'm trying to use QNetworkAccessManager to download files over https. And I found a strange thing: if the SSL libraries are not available to my application, then, as expected, the QNetworkAccessManager::get() request causes the QNetworkAccessManager::finished(QNetworkReply*) signal to be emitted. Inside the slot connected to this signal, I can read the error status (QNetworkReply::error()) and understand that the "TLS initialization failed" error occurred.
It's ok, but this is only the first time. If I make repeated attempts to execute QNetworkAccessManager::get(), the finished() signal is not emitted.
Why is that? I would like to get at least some response from QNetworkAccessManager on every request.

P.S. QNetworkReply::error() is not emitted too.

My system is Windows 10, Qt 5.14.1

ChrisW67
19th April 2020, 01:35
P.S. QNetworkReply::error() is not emitted too.
... and the QNetworkReply::sslErrors() signal ?

Dmitro25
19th April 2020, 04:59
... and the QNetworkReply::sslErrors() signal ?

Signal QNetworkReply::error() is only emitted for the first time (with code==QNetworkReply::UnknownNetworkError); signal QNetworkReply::sslErrors() is not emitted at all (neither the first time nor the subsequent)

Also, some Qt module writes the string "qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed" to the Application Output after each request.

ChrisW67
19th April 2020, 10:41
This could be reusing the failed connection from a cache rather than establishing a new one, thereby exercising a different code path.
Does the behaviour change if you call QNetworkAccessManager::clearConnectionCache() between gets?

When I have the Qt source code to hand I will have a look for the specific situation.

Dmitro25
19th April 2020, 11:26
Does the behaviour change if you call QNetworkAccessManager::clearConnectionCache() between gets?


Yes, thank you, it helps. Making clearConnectionCache() before each request solves the problem - finished() signal is emitted every time.

But I am doubtful, will using this method spoil the keep-alive connections?