- 
    
Bug
 - 
    Resolution: Done
 - 
    
P2: Important
 - 
    5.7.1
 - 
    None
 
On patform Ubuntu16.04 64 bit and RaspberryPi3
In one of my projects I noticed that; when I lose my internet connection and getting internet back a short time after that; the networkAccessibility keeps being nonAccessible.
After some debugging I noticed that in QNetworkAccessManager in createRequest a QDisabledNetworkReply was returned if networkAccessible == NotAccessible. 
And that a new session is started after that. So that will only happen when networkAccessible != NotAccessible.
(loosely related: There could also be some bugs in that networkAccessibleChanged is not always fired when I disconnect my internet during a request but that is another issue I think of which I do not have more details)
I must note that in my build I also incorperated this patch meant for 5.6.3 on 5.7.1:
https://bugreports.qt.io/browse/QTBUG-57110
https://codereview.qt-project.org/#/c/176831/
I got my ability to create successfull requests back after switching those 2 parts of code. As it looks like to me that you need to have tried to open a session to determine if there is a connection possible.
Therefore i have here my patch (which also contains the change mentioned above) (I must say that I dont fully understands the whole networking stuff architecture because I have not studied that):
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 587ab27..ac2c19c 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1161,12 +1161,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
     }
 
 #ifndef QT_NO_BEARERMANAGEMENT
-    // Return a disabled network reply if network access is disabled.
-    // Except if the scheme is empty or file://.
-    if (d->networkAccessible == NotAccessible && !isLocalFile) {
-        return new QDisabledNetworkReply(this, req, op);
-    }
-
     if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
         QNetworkConfigurationManager manager;
         if (!d->networkConfiguration.identifier().isEmpty()) {
@@ -1183,6 +1177,12 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
                 d->initializeSession = false;
         }
     }
+
+    // Return a disabled network reply if network access is disabled.
+    // Except if the scheme is empty or file://.
+    if (d->networkAccessible == NotAccessible && !isLocalFile) {
+        return new QDisabledNetworkReply(this, req, op);
+    }
 #endif
 
     QNetworkRequest request = req;
@@ -1605,7 +1605,7 @@ void QNetworkAccessManagerPrivate::_q_networkSessionClosed()
         QObject::disconnect(networkSession.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
         QObject::disconnect(networkSession.data(), SIGNAL(stateChanged(QNetworkSession::State)),
             q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)));
-        QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)),
+        QObject::disconnect(networkSession.data(), SIGNAL(error(QNetworkSession::SessionError)),
                             q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError)));
 
         networkSessionStrongRef.clear();