Crash when connection retry

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

nguyenman999
Posts: 6
Joined: 14 Jan 2015, 05:53

Crash when connection retry

Postby nguyenman999 » 09 Mar 2015, 09:32

Hi All!

I have 2 problems with smartfox connection:

1. App crash when smartfox connection retry:

void SmartFox::SendHandshakeRequest(bool isReconnection)
{
boost::shared_ptr<HandshakeRequest> req (new HandshakeRequest(*this->Version(), isReconnection ? *sessionToken : "", *clientDetails));
Send(req);
}

sessionToken become NULL when smartfox try to reconnect.

2. Smartfox connect function does not respone anything when connection is closed by server side after idle time. The specific scenario is:

- App idle
- After idle time server close connection
- Client receive event Connection Lost
- Client call function connect to server again
- And then client does not receive any event after call connect function.

That my current connection problems, please help me! Thanks.
User avatar
Bax
Site Admin
Posts: 4340
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Crash when connection retry

Postby Bax » 10 Mar 2015, 16:56

We will shortly investigate issue #1.
About issue #2, after a disconnection you have to create a new SmartFox object, you can't reuse the existing one.
Paolo Bax
The SmartFoxServer Team
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Crash when connection retry

Postby MBagnati » 11 Mar 2015, 01:03

Hi,
About the issue #1, please implement the following fix.
Open file SmartFox.cpp and move at the begin of method SmartFox::Reset()
Here, insert these statements

Code: Select all

   if ((bitSwarm != NULL) && (bitSwarm->ReconnectionSeconds() > 0))
   {
      return;
   }


So, updated method will be

Code: Select all

void SmartFox::Reset()
{
   if ((bitSwarm != NULL) && (bitSwarm->ReconnectionSeconds() > 0))
   {
      return;
   }

   bbConnectionAttempt = 0;
        ...
        ...
        ...

Let us know if it solves the crash
nguyenman999
Posts: 6
Joined: 14 Jan 2015, 05:53

Re: Crash when connection retry

Postby nguyenman999 » 11 Mar 2015, 03:59

Hi,

Thanks for your help, After apply this code the problem 1 is gone. But I have another issue with problem 2 when I dispose smartfox instance.

When I call dispose function of smartfox instance it happen others 2 problems:
- App crash at function processEvent()

for (iterator = events.begin() ; iterator < events.end(); iterator++)
{
boost::shared_ptr<BaseEvent> evt = *iterator;

Dispatcher()->DispatchEvent(evt); // Crash here

// Cleanup
CleanEventParams(evt);
}

- App lock at function dispose() of BitwarmClient

if (socket != NULL)
{
lockDispose.lock(); // App freeze here

boost::shared_ptr<ConnectionDelegate> delegateConnection = boost::shared_ptr<ConnectionDelegate>();
socket->OnConnect(delegateConnection);

boost::shared_ptr<ConnectionDelegate> delegateDisconnection = boost::shared_ptr<ConnectionDelegate>();
socket->OnDisconnect(delegateDisconnection);

boost::shared_ptr<OnDataDelegate> delegateOnData = boost::shared_ptr<OnDataDelegate>();
socket->OnData(delegateOnData);

boost::shared_ptr<OnErrorDelegate> delegateOnError = boost::shared_ptr<OnErrorDelegate>();
socket->OnError(delegateOnError);

lockDispose.unlock();
}

Please help me solve this issue, Thanks
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Crash when connection retry

Postby MBagnati » 11 Mar 2015, 11:22

Hi,
I am not able to reproduce your crash.
Could you give me additional info about the context where you call Dispose?
Please take a look at SimpleChat sample. Are you able to get the crash using this sample?
In this sample the Dispose is called inside the OnDestroy of main window and, on my computer, I have not any crash.

Code: Select all

void CMainFrame::OnDestroy()
{
   if (m_ptrSmartFox != NULL)
   {
      m_ptrSmartFox->Disconnect();
      m_ptrSmartFox->Dispose();
      m_ptrSmartFox = NULL;
   }

   CFrameWndEx::OnDestroy();
}

Please, can you also check that you have called Disconnect method to terminate all I/O tasks before than Dispose? (see sample code above)
nguyenman999
Posts: 6
Joined: 14 Jan 2015, 05:53

Re: Crash when connection retry

Postby nguyenman999 » 12 Mar 2015, 08:27

Hi!

I also use this code to check in case we have wifi on it work correctly, But in case wifi off app also freeze in dispose method.
if (smartFox)
{
CCLOG("disconnectToServer: smartFox->Dispose() start");
smartFox->Disconnect();
smartFox->Dispose(); // App freeze here when we don't have network connection (on mobile device wifi off, or out of wifi range)
CCLOG("disconnectToServer: smartFox->Dispose() end");
}
On PC I tested by disable network adapter.

Thanks for your response!
MBagnati
Posts: 125
Joined: 12 Feb 2013, 10:57

Re: Crash when connection retry

Postby MBagnati » 16 Mar 2015, 07:42

Hi,
To investigate the issue, I have done these tests:

Test #1
I have disabled the wi-fi network card from Windows panel "Network Connections".
Then I have started the SimpleChat sample.
Of course, SimpleChat is not able to connect to SmartFox Server (because the wi-fi network is disabled), so after few seconds it shows the message "Timeout establishing connection with SmartFoxServer".
At this point I have terminated the SimpleChat application closing its main windows
Looking at the source code, I see that method CMainFrame::OnDestroy() is called and it is executed without any freeze (Smartfox Disconnect and Dispose functions called from OnDestroy are executed without freeze).

Test #2
My wi-fi network card is working.
I start the SimpleChat sample.
SimpleChat establishes the connection with SmartFoxServer by the IP channel and all is working.
At this point, I disable the wi-fi network card from Windows panel "Network Connections".
After a couple of seconds, SimpleChat detects the fault of the connection with SmartFoxServer and shows the login page.
I terminate the SimpleChat application closing its main windows
Looking at the source code, I see that method CMainFrame::OnDestroy() is called and it is executed without any freeze (Smartfox Disconnect and Dispose functions called from OnDestroy are executed without freeze).

Please, can you perform an additional test to help me to investigate the issue?
Can you use the SimpleChat sample to repeat the above tests to check the behaviour of login and disconnect when you disable your wi-fi card?
nguyenman999
Posts: 6
Joined: 14 Jan 2015, 05:53

Re: Crash when connection retry

Postby nguyenman999 » 23 Mar 2015, 09:34

Thanks for your response my issue!

I have find out my problems. My app freeze because when connection lost i try to make new request to connect to server (at that time network adapter was disable) so that request is pending and block IO because smartfox have no event back when connection cannot establish. So I have to make counter to count down 10s to dispose smartfox instance. So that my app freeze at dispose function of smartfox.

My solution is: When connection lost I call function smartfox->disconnect(), and then smartfox->dispose(). And then I make new smartfox instance to reconnect to my server.

Thanks for your help very much!

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 1 guest