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.

Qt Code:
  1. if (!scheduledLookups.isEmpty()) {
  2. // try to start the new ones
  3. QMutableListIterator<QHostInfoRunnable*> iterator(scheduledLookups);
  4. while (iterator.hasNext()) {
  5. QHostInfoRunnable *scheduled = iterator.next();
  6.  
  7. // check if a lookup for this host is already running, then postpone
  8. for (int i = 0; i < currentLookups.size(); i++) {
  9. [B]if (currentLookups.at(i)->toBeLookedUp == scheduled->toBeLookedUp) { //line:506
  10. iterator.remove();
  11. postponedLookups.append(scheduled);
  12. scheduled = 0; //line:509
  13. break;
  14. }[/B]
  15. }
  16.  
  17. [B] if (scheduled && threadPool.tryStart(scheduled)) { //line:514 [/B]
  18. // runnable now running in new thread, track this in currentLookups
  19. iterator.remove();
  20. currentLookups.append(scheduled);
  21. } else if (scheduled) {
  22. // wanted to start, but could not because thread pool is busy
  23. break;
  24. } else {
  25. // was postponed, continue iterating
  26. continue;
  27. }
  28. };
  29. }
To copy to clipboard, switch view to plain text mode 

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