Opened 11 months ago

Closed 9 months ago

#18492 closed defect (duplicate)

wxSocket Client crashes inside wxThread

Reported by: evstevemd Owned by:
Priority: normal Milestone:
Component: network Version: dev-latest
Keywords: wxSocket Cc: mwinjilisti@…
Blocked By: Blocking:
Patch: no

Description

I have Simple wxSocketClient code that is working but keep crashing. Most of the time it works but sometimes it crashes two or more times before it works. I have tried for so long to make sense of the trace but could not.

Here it is

(lldb) bt
* thread #12, stop reason = EXC_BAD_ACCESS (code=1, address=0x18)
  * frame #0: 0x00007fff6659134c libsystem_pthread.dylib`pthread_mutex_lock
    frame #1: 0x00007fff3e30db70 CoreFoundation`CFSocketDisableCallBacks + 64
    frame #2: 0x0000000101ab0135 libwx_baseu_net-3.1.dylib`wxSocketManagerMac::Uninstall_Callback(this=0x0000000101ac93e8, socket_=0x000000010a94a660, event=wxSOCKET_INPUT) at sockosx.cpp:268
    frame #3: 0x0000000101ab083e libwx_baseu_net-3.1.dylib`(anonymous namespace)::wxSocketImplMac::DoClose(this=0x000000010a94a660) at sockosx.cpp:69
    frame #4: 0x0000000101a9ed1b libwx_baseu_net-3.1.dylib`wxSocketImpl::Close(this=0x000000010a94a660) at socket.cpp:564
    frame #5: 0x0000000101a9e8ab libwx_baseu_net-3.1.dylib`wxSocketImpl::Shutdown(this=0x000000010a94a660) at socket.cpp:574
    frame #6: 0x0000000101aa0d2c libwx_baseu_net-3.1.dylib`wxSocketBase::ShutdownOutput(this=0x0000000104072360) at socket.cpp:960
    frame #7: 0x0000000101aa0cc2 libwx_baseu_net-3.1.dylib`wxSocketBase::Close(this=0x0000000104072360) at socket.cpp:950
    frame #8: 0x0000000101aa42e2 libwx_baseu_net-3.1.dylib`wxSocketClient::DoConnect(this=0x0000000104072360, remote=0x0000000104072a70, local=0x0000000000000000, wait=false) at socket.cpp:2001
    frame #9: 0x0000000101aa45d1 libwx_baseu_net-3.1.dylib`wxSocketClient::Connect(this=0x0000000104072360, remote=0x0000000104072a70, wait=false) at socket.cpp:2055
    frame #10: 0x00000001023af176 libApp.dylib`App::AppClientTCP::Connect() + 86
    frame #11: 0x00000001000b5102 Studio`AppServerProxy::Entry(this=0x0000000104071f70) at Appserverproxy.cpp:76
    frame #12: 0x0000000101cae221 libwx_baseu-3.1.dylib`wxThread::CallEntry(this=0x0000000104071f70) at thrimpl.cpp:356
    frame #13: 0x0000000101cadc81 libwx_baseu-3.1.dylib`wxThreadInternal::PthreadStart(thread=0x0000000104071f70) at threadpsx.cpp:869
    frame #14: 0x0000000101caeec5 libwx_baseu-3.1.dylib`wxPthreadStart(ptr=0x0000000104071f70) at threadpsx.cpp:819
    frame #15: 0x00007fff66593661 libsystem_pthread.dylib`_pthread_body + 340
    frame #16: 0x00007fff6659350d libsystem_pthread.dylib`_pthread_start + 377
    frame #17: 0x00007fff66592bf9 libsystem_pthread.dylib`thread_start + 13
(lldb)

Here is the Socket code.

AppClientTCP::AppClientTCP(int port, wxEvtHandler *handler)
    : AppClientBase(handler)
{
    wxCriticalSectionLocker locker(m_sockCS);
    m_socket = new wxSocketClient(wxSOCKET_BLOCK | wxSOCKET_WAITALL);
    m_socket->Notify(false);

    m_addr.AnyAddress();
    m_addr.Service(port);

    Connect();
}


bool AppClientTCP::Connect()
{
    wxCriticalSectionLocker locker(m_sockCS);
    m_socket->Connect(m_addr, false);
    return m_socket->WaitOnConnect(0, 400); // 0sec 400ms
}

bool AppClientTCP::IsConnected()
{
    wxCriticalSectionLocker locker(m_sockCS);
    return m_socket->IsConnected();
}

AppClientTCP::~AppClientTCP() { wxDELETE(m_socket); }

Here is a proxy code

AppServerProxy::AppServerProxy(...)
    : wxThread(wxTHREAD_JOINABLE)
    //....
{
    m_app = AppClientTCP::Ptr_t(new AppClientTCP(cparams.GetPort(), m_evtHandler));
    m_app->Connect();
}

AppServerProxy::~AppServerProxy() { m_app->ShutDown(); }

wxThread::ExitCode AppServerProxy::Entry()
{
    while(!TestDestroy()) {
        if(!m_app) {
            wxPuts("App IS DEAD");
            continue;
        }

        if(m_app->IsConnected()) {
            //some work here
        }
        else
        {
            wxThread::Sleep(500);
            m_app->Connect();
        }
    }
    return (wxThread::ExitCode)0;
}

Am not sure why I face this and have no idea where to start solving this

Change History (2)

comment:1 Changed 10 months ago by evstevemd

  • Cc mwinjilisti@… added

seems to be related to https://github.com/facebook/SocketRocket/issues/339#issuecomment-220812054

I will cross check the code and see if it is indeed the cause

comment:2 Changed 9 months ago by vadz

  • Resolution set to duplicate
  • Status changed from new to closed

Same as #15259.

Note: See TracTickets for help on using tickets.