Archived Forum Post

Index of archived forum posts

Question:

VC++ 6.0 CkHttp hangs up in delete/destructor until time-out met

May 04 '16 at 14:13

I'm doing an http request in its own thread, which waits for it to be finished (a 180 second timeout) or for the user to abort it.

Using the background mode, I expected to be able to abort the request. Even though I call BgTaskAbort, it hangs up trying to return from the function that creates the CkHttp object. It seems that the CkHttp destructor waits for the timeout to be finished before returning. The same thing happens if I use "new" to create the CkHttp object and "delete" to delete it -- it will not return from the "delete" call until the 180 seconds has elapsed.

Here's a code snippet:

bool Request()
{
  CkHttp http;
  CkHttpRequest req;

/// (code to set up req...)

  http.put_UseBgThread(true);

  CkHttpResponse *resp = 0;
  http.put_ConnectTimeout(180);
  http.put_ReadTimeout(180);
  resp = http.SynchronousRequest (g_strDomain, g_nPort, true, req);
  // resp is not expected to be valid yet....

  // now start waiting
  int nCount = 0;
  BOOL fFinished = (http.get_BgTaskRunning() != true);
  // m_fGiveUp is set in another thread if Abort button clicked
  while (!m_fGiveUp && !fFinished && nCount*4 < 180)
  {
    http.SleepMs (250);  // check once per 1/4 second
    nCount++;
    fFinished = (http.get_BgTaskRunning() != true);
  };

  if (!fFinished)
  {
    // "Abort" clicked...
    http.BgTaskAbort();
    m_fGaveUp = TRUE;
    return FALSE;
//// HANGS UP HERE WAITING FOR CKHTTP TO BE DELETED BEFORE LEAVING THE FUNCTION
  }
}

So, am I doing something wrong? Is there any way around this?

I also tried making the CkHttp object static, which did let it leave the function immediately, but then when another request is made it would hang up (presumably waiting for the first one to time out).

Note: I am using a version from 2010. Tried to use the new version 9.5, but wouldn't compile without changes to my code (some of the Mail/MailMan functions changed, so I'm not ready to migrate yet. If this was a known bug that has since been fixed, let me know and I'll make the effort.


Answer

You can try calling CkHttp.CloseAllConnections. I don't know if that would help.

Your code is using an older async scheme that was deprecated. It should changed to use the Chilkat standard for async (where each method that can be asynchronous has a corresponding method ending with "Async" and it returns a CkTask).

I don't know if the hangup was due to the older deprecated "Bg" methods, or if it was due to something else. I created a latest pre-release (v9.5.0.58) you can try here: http://www.chilkatsoft.com/download/preRelease/chilkat-9.5.0-x86-vc6.zip


Answer

Thank you for the response.

I don't have the CloseAllConnections function, so that must have been added later. It sounds like my only option to fix this would be to use the newer version. It's just a pain to have to go through and change a bunch of code due to class API changes, hoping it still works the same way, and then have to re-test everything. (That's why I still use VC++ 6.0 -- I don't have the manpower to rewrite and re-test an entire system that has been fine-tuned and debugged over 15 years. ;-)


Answer

I don't suppose there's a (brief) list somewhere that outlines changes that need to be done to migrate from one version to another? Like the MailMan function changes for attaching a file, etc, and how to convert the CkHttp Synchronous/Bg functions to the Async functions... The release notes (given the time to go through them) may tell me that something changed, but not how to convert my code as far as I've seen.