Archived Forum Post

Index of archived forum posts


Crash in CkSocket.AsyncConnectStart()

Oct 01 '12 at 20:51

The following crashes for me:

void crash()
    for (int i = 0; i <= 2; ++i)
        CkSocket socket;
        if (socket.UnlockComponent("XXXyourCodeXXX") != true) {
            printf("%s\n", socket.lastErrorText());
        if (socket.AsyncConnectStart( "blah", 24, true, 1 ) != true) {
        while ((socket.get_AsyncConnectFinished() != true)) {

The exception is thrown somewhere in CkSocket library, in its own thread, at around HostnameResolveIpv6:resolveHostname. The problem appears to be that AsyncConnectStart() spawns its own dns lookup thread, which is not properly shut down on destruction of the CkSocket object. As you can see, I do wait for get_AsyncConnectFinished() to return true before killing the CkSocket. But this function appears to be lying, because it should return false if it owns an outstanding dns lookup thread, which would avoid this crash. Another solution would be to add a Join() or Wait() method to CkSocket, which allowed my program to wait until CkSocket's sub-threads are all done before I delete it. You could also make Close() properly shut down any open child threads.

Probably the best solution is to have get_AsyncConnectFinished() properly report false if there are open threads while also properly killing any open threads on destruction.

Accepted Answer

Here's the new build that should fix the problem:

If not, then please let me know..


I fixed the problem. No changes to your code are required. What operating system, architecture (32-bit / 64-bit), VC++ version (if Windows), etc. do you use? I can provide a new build later this weekend once I know..