Potential Problem with isValidUserToken

This may be by design but I have noticed the following and think it may be a problem.
If there is an active internet connection and isValidUserToken() is called in iOS, the bool is returned true or false as expected.
However, if the internet connection is disabled, I’ve noticed the following behavior.
Case 1: The user has previously logged in so there should be a valid user token. When isValidUserToken is called an error is thrown.
Case 2: The user has not previously logged in so there shouldn’t be a valid user token. When isValidUserToken is called an error is not thrown. The API returns false. Maybe this is by design, but if there isn’t an active internet connection, I am not sure how the API would know if there is a valid token or not.

Hi, Jon.

We will need some time to investigate this issue and get back to you.
Thanks for reporting!

Hi Jon,

By looking at the code, if you call this method first with the argument of “true”, then an error will be thrown from isValidUserToken():

Regards,
Mark

That’s true but if the user token is not valid, then false is returned when there is no connection. My belief was that is should throw the same error. If it can’t connect to Backendless then it wouldn’t know if it was false. In theory, regardless of it’s true or false it should throw an error because it can’t connect. Maybe my thinking is wrong but that’s the way it made sense to me.

Take care,

Jon

This issue is fixed, you could update the latest Backendless SDK via CocoaPods (3.0.31 release) or from ios-SDK github (CommLibiOS and backendless).

Excellent. Thank you.

I have been testing with the new 3.0.31 SDK and have noticed the following issues. There are four case scenarios as I see it. I have listed each below and have shown the results for each.

User is Logged In && Internet is Active

  1. isUserTokenValid returns “true”. Working as expected.

User is Not Logged In && Internet is Active

  1. FAULT = ‘3904’ [user is not logged in] <user is not logged in>
  2. I believe this should return “false” not “3904”. My understanding of isUserTokenValid is that it returns a bool. If the user is logged out, then the user token should not be valid and false should be returned.

User is Logged In && Internet is Inactive

  1. FAULT = ‘-1009’ [NSURLErrorDomain] <The Internet connection appears to be offline.>
  2. The app crashes after the CPU and memory builds. The error message is listed below.

User is Not Logged In && Internet is Inactive

  1. FAULT = ‘3904’ [user is not logged in] <user is not logged in>
  2. I believe this should return something other than “3904” since there would be no way for the app to know if the user was or was not logged in since there is no internet connection. This parallels the original issue.
  3. The app crashes after the CPU and memory builds. The error message is listed below.

I am not saying that the SDK is the result of the crash but I have not seen this prior to the update to 3.0.31. If I bypass the isUserTokenValid method call, the app does not crash.

[Invoker invokeSync:method:args:]:

    0x1098d26f5 &lt;+0&gt;:   pushq  %rbp

    0x1098d26f6 &lt;+1&gt;:   movq   %rsp, %rbp

    0x1098d26f9 &lt;+4&gt;:   pushq  %r14

    0x1098d26fb &lt;+6&gt;:   pushq  %rbx

    0x1098d26fc &lt;+7&gt;:   movq   %rdi, %rbx

    0x1098d26ff &lt;+10&gt;:  movq   0xd24da(%rip), %rax       ; Invoker.client

    0x1098d2706 &lt;+17&gt;:  movq   (%rbx,%rax), %rdi

    0x1098d270a &lt;+21&gt;:  movq   0xcee9f(%rip), %rsi       ; "invoke:method:args:"

    0x1098d2711 &lt;+28&gt;:  callq  *0x79de1(%rip)            ; (void *)0x000000010d965800: objc_msgSend

    0x1098d2717 &lt;+34&gt;:  movq   %rax, %r14

    0x1098d271a &lt;+37&gt;:  movq   0xd24c7(%rip), %rax       ; Invoker._throwException

    0x1098d2721 &lt;+44&gt;:  cmpb   $0x0, (%rbx,%rax)

    0x1098d2725 &lt;+48&gt;:  je     0x1098d2751               ; &lt;+92&gt; at Invoker.m:120

    0x1098d2727 &lt;+50&gt;:  movq   0xd12fa(%rip), %rdi       ; (void *)0x00000001099a9bd8: Fault

    0x1098d272e &lt;+57&gt;:  movq   0xcce03(%rip), %rsi       ; "class"

    0x1098d2735 &lt;+64&gt;:  movq   0x79dbc(%rip), %rbx       ; (void *)0x000000010d965800: objc_msgSend

    0x1098d273c &lt;+71&gt;:  callq  *%rbx

    0x1098d273e &lt;+73&gt;:  movq   0xcec8b(%rip), %rsi       ; "isKindOfClass:"

    0x1098d2745 &lt;+80&gt;:  movq   %r14, %rdi

    0x1098d2748 &lt;+83&gt;:  movq   %rax, %rdx

    0x1098d274b &lt;+86&gt;:  callq  *%rbx

    0x1098d274d &lt;+88&gt;:  testb  %al, %al

    0x1098d274f &lt;+90&gt;:  jne    0x1098d2759               ; &lt;+100&gt; at Invoker.m:118

    0x1098d2751 &lt;+92&gt;:  movq   %r14, %rax

    0x1098d2754 &lt;+95&gt;:  popq   %rbx

    0x1098d2755 &lt;+96&gt;:  popq   %r14

    0x1098d2757 &lt;+98&gt;:  popq   %rbp

    0x1098d2758 &lt;+99&gt;:  retq   

    0x1098d2759 &lt;+100&gt;: movq   %r14, %rdi

    0x1098d275c &lt;+103&gt;: callq  0x10991490a               ; symbol stub for: objc_exception_throw

Jon, how do you make an “Internet is Inactive” state - with Airplane Mode?

I need to reproduce your workflow.

I am disabling wifi on my computer and using the simulator.

Hi Jon,

I have created a test sample project, it makes user login and then calls isValidUserToken() one time per second. I started it with internet, then disabled wifi, and app worked during 5 hours without any crashes.

Please check my project (see in attachment) - it created with latest Backendless SDK 3.0.31.
How it will work for you? Could you make some changes to reproduce the crashes which is described above? Maybe you can provide your sample project, which demonstrates the issue - here or to support@backendless.com?

Regards,
Slava

TestValidUserToken.zip (19.56MB)

Sure, the logic have to be following:
User is Logged In && Internet is Active
isUserTokenValid returns “true”.

User is Not Logged In && (Internet is Active || Inactive)
isUserTokenValid returns “false”. If the user is logged out, then the user token should not be valid.

User is Logged In && Internet is Inactive
FAULT = ‘-1009’ [NSURLErrorDomain] <The Internet connection appears to be offline.>

I will test and get back to you. Please give me a bit of time.

When I run your project with wifi disabled, the user will not be able to connect to Backendless to login. Therefore isUserTokenValid should return false as you mentioned above. However it reports error 3904.

The same error report is presented with wifi enabled and without a user logged in. To test this I commented out the login method in your sample project. The project reports 3904 not false.

The screenshots below show the error logs and you can see that wifi is turned on/off for the two scenarios. The app does not crash like you mentioned. I will investigate why my app is crashing.

The app has stopped crashing after I made some changes. It’s definitely not a Backendless issue.

“false” instead 3904 - please update pod 3.0.32 release.

Excellent. Thank you for addressing this. I am updating to 3.0.32 and will test later today. Unbelievable support is offered here.

This is working as expected now. Thanks for all of the help.