PDA

View Full Version : QNetworkAccessManager not able to connect after computer wakes up



vision06
30th April 2010, 20:21
Hello,

I have seen a peculiar problem with QNetworkAccessManager not being able to connect after my computer comes back from sleep mode. This is the setup, I have an application that uses QNetworkAccessManager to connect to a website every 60 seconds. Everything works great. But if the computer goes to sleep for a long time. When it wakes up it does not work. QNetworkAccessManager never emits any signals. I have tested on Windows XP, Windows Vista.

I found out that there is a problem with the Host Lookup code inside the QT framework. I fixed the problem by not using DNS lookup.

Inside Qt\2010.02.1\qt\src\network\kernel\qhostinfo.cpp(Q HostInfoLookupManager::work()) the new DNS requests are queued up. The problem is that this function never schedules another DNS lookup because toBeLookedUp is the same as the previous request that never finished (line:506). Therefore, QNetworkAccessManager never connects because it is waiting for the DNS lookup to comeback with the ip address of the server. Line:514 schedules the DNS lookup work only if scheduled is not NULL but line:509 sets scheduled to NULL every time.



if (!scheduledLookups.isEmpty()) {
// try to start the new ones
QMutableListIterator<QHostInfoRunnable*> iterator(scheduledLookups);
while (iterator.hasNext()) {
QHostInfoRunnable *scheduled = iterator.next();

// check if a lookup for this host is already running, then postpone
for (int i = 0; i < currentLookups.size(); i++) {
if (currentLookups.at(i)->toBeLookedUp == scheduled->toBeLookedUp) { //line:506
iterator.remove();
postponedLookups.append(scheduled);
scheduled = 0; //line:509
break;
}
}

if (scheduled && threadPool.tryStart(scheduled)) { //line:514
// runnable now running in new thread, track this in currentLookups
iterator.remove();
currentLookups.append(scheduled);
} else if (scheduled) {
// wanted to start, but could not because thread pool is busy
break;
} else {
// was postponed, continue iterating
continue;
}
};
}


I was wondering if any body has seen this problem before.

minimoog
3rd May 2010, 07:56
I have seen it. QNetworkAccessManager sometimes works, sometimes doesn't after waking (Windows 7 here). Like you said, it's just never sends any signal.

Did you reported bug to the Nokia?

vision06
5th May 2010, 15:48
Yes I did report it to Nokia. This is what they told me.

QTBUG-10286.
----------------------------------

Resolution: Incomplete

We've done some bugfixes in work() in the last days.
Can you please test with a Qt compiled from http://qt.gitorious.org/qt/qt/commits/4.6 ? (see the .tar.gz link on the right side).

I will be testing it with their code from their repo to see if their bug fixes will fix this problem. I will also report what I find here.:)