internal crash when parsing a message

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

internal crash when parsing a message

Postby rafaelb149 » 30 Aug 2020, 13:30

Hi

I'm using SFS client version 1.7.10 and I observe random crash in production on iOS platform only.
All I have is the stack trace, so I hope it's enough for you to understand what is happening there:

Code: Select all

CoreFoundation                 0x1be1c5344 __exceptionPreprocess
1  libobjc.A.dylib                0x1bdedacc0 objc_exception_throw
2  Foundation                     0x1be4f20d4 -[NSString hash]
3  BigCasino                      0x102ef7ae8 -[Data readUTF] + 127 (Data.m:127)
4  BigCasino                      0x102efaf3c -[DefaultSFSDataSerializer decodeSFSObject:] + 355 (DefaultSFSDataSerializer.m:355)
5  BigCasino                      0x102efb828 -[DefaultSFSDataSerializer decodeObject:] + 445 (DefaultSFSDataSerializer.m:445)
6  BigCasino                      0x102efaf68 -[DefaultSFSDataSerializer decodeSFSObject:] + 357 (DefaultSFSDataSerializer.m:357)
7  BigCasino                      0x102efdf1c -[DefaultSFSDataSerializer binary2object:] + 790 (DefaultSFSDataSerializer.m:790)
8  BigCasino                      0x102f1f138 +[SFSObject newFromBinaryData:] + 36 (SFSObject.m:36)
9  BigCasino                      0x102f24074 -[SFSProtocolCodec onPacketRead:] + 88 (SFSProtocolCodec.m:88)
10 BigCasino                      0x102f1cfe4 -[SFSIOHandler handlePacketData:] + 94 (SFSIOHandler.m:94)
11 BigCasino                      0x102f1e310 -[SFSIOHandler onDataRead:] + 244 (SFSIOHandler.m:244)
12 BigCasino                      0x102eec380 -[BitSwarmClient stream:handleEvent:] + 466 (BitSwarmClient.m:466)
13 CoreFoundation                 0x1be1599a0 _signalEventSync
14 CoreFoundation                 0x1be1568e8 _cfstream_solo_signalEventSync
15 CoreFoundation                 0x1be1566e0 _CFStreamSignalEvent
16 CFNetwork                      0x1c152df70 _CFStreamErrorFromCFError
17 CFNetwork                      0x1c15384d8 _CFStreamErrorFromCFError
18 CoreFoundation                 0x1be14d080 __CFSocketPerformV0
19 CoreFoundation                 0x1be140d14 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
20 CoreFoundation                 0x1be140c68 __CFRunLoopDoSource0
21 CoreFoundation                 0x1be1403c4 __CFRunLoopDoSources0
22 CoreFoundation                 0x1be13b1fc __CFRunLoopRun
23 CoreFoundation                 0x1be13abc8 CFRunLoopRunSpecific
24 GraphicsServices               0x1c851c5cc GSEventRunModal
25 UIKitCore                      0x1c22ed744 UIApplicationMain
26 BigCasino                      0x103247328 gameplay::Platform::enterMessagePump() + 1713 (PlatformiOS.mm:1713)
27 BigCasino                      0x10322eb48 main + 135 (gameplay-main-ios.mm:135)
28 libdyld.dylib                  0x1bdfb7384 start


Let me know if you need more information.
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 30 Aug 2020, 14:02

It seems like it somehow related to HRC, because we have started observed those crashes since the date we enabled the HRC.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 30 Aug 2020, 20:52

Hi,
the stack trace doesn't suggest this is connected with HRC.
We would need more details on how to reproduce the issue. Can you recreate the problem locally?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 01 Sep 2020, 08:26

We don't succeed to reproduce it in QA, actually we don't know how to do it.
All I can say that it was observed only after enabling HRC in our server.
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 15 Sep 2020, 14:23

Hi

This crash keep happening in our production environment.
How can we make a progress here? (We haven't succeeded to reproduce this issue yet)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 15 Sep 2020, 16:57

Without knowing the input data that triggers this issue it's impossibile to guess what might be going on.
Is this error occurring vert often? The % of occurrence would also help understand if this is something random, maybe caused by a network error (which would explain why you can't reproduce it locally)

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 16 Sep 2020, 13:39

This problem is not so often, but it happens 100 times per day for around 200K active users, so it's rare.
I told you that the problem appeared after enabling the HRC+ feature, may it be related to some corrupted message that was received via the HRC machnism?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 16 Sep 2020, 14:05

Hi,
100 instances in 200K DAU is a very low occurrence. It's < 0.1%.
My hypothesis of a network error fits this kind of low occurrence. Over an unstable internet connection it can happen that a packet gets corrupted and the Serializer is unable to decode the data.

From the stack trace there is nothing pointing to HRC specific code, but it may be that there's a connection with it.
When users have an unstable connection it is more likely that the HRC will be triggered (because of a sudden disconnection) and maybe right after the reconnection their network is still unstable and that's when the unrecoverable error occurs.

Given the very low frequency of the problem I don't think there's many other explanations.
Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 16 Sep 2020, 14:44

But should it crash?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 17 Sep 2020, 07:02

I think that depends on whether or not the exception is ever caught at some point in the call stack.
Is your game a native iOS app or are you using a third party tool (such as Unity) to generate the iOS binary?

If you have control over the Objective-C/Swift code you can add a try/catch block at the top of your code to catch any unexpected exceptions.

Take a look at this topic here:
https://stackoverflow.com/questions/950 ... tion-throw

See the 2nd answer. It shows different ways of catching unexpected exceptions.
Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 13 Dec 2020, 14:43

Sorry for the long delay.

I'm using Crashlytics for collecting all exceptions and crash in my app.
I will open a ticket for Crashlytics about why they crash.
But beforehand, why your code doesn't handle this exception internally?
Is this situation for throwing such an exception from your side is acceptable or something fatal happened?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 14 Dec 2020, 08:05

Is this situation for throwing such an exception from your side is acceptable or something fatal happened?

We're not throwing an exception from our side.
This is an unexpected runtime error, where the protocol codec fails because the data coming from the network is corrupted, which should be a pretty rare occurrence, but it can happen.

As regards catching it, we could but then we would need to rethrow it anyways because if such error happens it's fatal. Meaning that if the protocol stream breaks there is no way to recover it.

My suggestion would be to catch it yourself (see the stacktrace article I linked in my previous post) and decide what do you want to do with it. Such as showing a message to the player telling that the connection broke down.

Makes sense?
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 14 Dec 2020, 11:55

What should I do with this exception? I expect Crashlytics to catch this exception anyway.
But let's say I will catch it manually, will SF continue to work or the connection is broken? if yes, I would expect you to catch it and call to onServerConnetionLost with unknown reason
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: internal crash when parsing a message

Postby Lapo » 14 Dec 2020, 16:33

As I mentioned if this error occurs the connection is broken and there is no reliable way to make it work again.
will SF continue to work or the connection is broken?

The server will continue to work, no problem :)
The only issue is the client side. You should just call the disconnect() method manually, dereference/destroy the SmartFox client object, re-create a new one and start over.

if yes, I would expect you to catch it and call to onServerConnetionLost with unknown reason

No, because this is an issue with bad network data, not with a disconnection. They are two different things.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
rafaelb149
Posts: 25
Joined: 28 Jun 2020, 08:54

Re: internal crash when parsing a message

Postby rafaelb149 » 14 Dec 2020, 16:56

Thanks for the detailed answer.
Let's say I will catch all of the uncached exceptions in my app, I don't think Crashlyics will like that.
Let's say they will like it :), then how should I know where this exception came from? NSRangeException can be raised from many methods, there is another way to catch it in some more specific hierarchy level?

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 18 guests