New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with wifi disabled and bad network on todo app #2196

Closed
sridevi-15 opened this Issue Aug 27, 2018 · 9 comments

Comments

Projects
None yet
6 participants
@sridevi-15

sridevi-15 commented Aug 27, 2018

Environment

  • Version: 2.1.0-163
  • Client OS: iOS
  • Server: sg version 2.1.0-121

Steps to reproduce :

  1. Open todo app, create lists and tasks and share with user1.
  2. close the app, disable the wifi and set network link condition with bad network.
  3. Have user1 update some docs.
  4. Now enable the wifi and open the app

Expected Restult :

Verify docs updated on todo app with updates which user1 made

Result :

Seeing crash on the logs

logs :

https://gist.github.com/sridevi-15/8d357d8c8cd8ff9927c0a794209b6306
https://gist.github.com/sridevi-15/06324ac41645f766ef4b4f80d9b61a12

@sridevi-15 sridevi-15 added this to the 2.1.0 milestone Aug 27, 2018

@pasin pasin added the crash! label Aug 28, 2018

@pasin pasin self-assigned this Aug 28, 2018

@pasin

This comment has been minimized.

Contributor

pasin commented Aug 28, 2018

Captured from the 2nd log,

2018-08-27 16:01:52.014225-0700 Todo[3252:3316223] SocketStream read error [0x10a727560]: 1 49
2018-08-27 16:01:52.014367-0700 Todo[3252:3316223] CouchbaseLite WS Verbose: DoRead read 18446744073709551615 bytes
2018-08-27 16:01:52.014409-0700 Todo[3252:3316223] CouchbaseLite WS Verbose: <<< received 18446744073709551615 bytes [now 3 pending]

2018-08-27 16:01:52.052498-0700 Todo[3252:3310545] CouchbaseLite Sync Info: CBLReplicator[<*> URL[ws://ec2-54-164-174-27.compute-1.amazonaws.com:4984/todo]]: Set suspended = 0 (suspending = 1)
Todo(3252,0x16f4db000) malloc: *** mach_vm_map(size=4294983680) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
(lldb) bt
CouchbaseLiteSwift was compiled with optimization - stepping may behave oddly; variables may not be available.
warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.
* thread #89, queue = 'WebSocket to ec2-54-164-174-27.compute-1.amazonaws.com:4984', stop reason = signal SIGABRT
    frame #0: 0x00000001821592e0 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000001822fa288 libsystem_pthread.dylib`pthread_kill$VARIANT$mp + 376
    frame #2: 0x00000001820c7d0c libsystem_c.dylib`abort + 140
    frame #3: 0x00000001818632c8 libc++abi.dylib`abort_message + 132
    frame #4: 0x0000000181863458 libc++abi.dylib`default_terminate_handler() + 280
    frame #5: 0x000000018188c8e4 libobjc.A.dylib`_objc_terminate() + 140
    frame #6: 0x000000018187d37c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x000000018187d400 libc++abi.dylib`std::terminate() + 84
    frame #8: 0x00000001012f8588 CouchbaseLiteSwift`__clang_call_terminate + 12
  * frame #9: 0x000000010136bc0c CouchbaseLiteSwift`::c4socket_received(socket=<unavailable>, data=<unavailable>) at c4Socket.cc:186 [opt]
    frame #10: 0x00000001012f57a8 CouchbaseLiteSwift`::-[CBLWebSocket callC4Socket:](self=0x0000000108612710, _cmd=<unavailable>, callback=<unavailable>)(C4Socket *)) at CBLWebSocket.mm:238 [opt]
    frame #11: 0x00000001012f6b68 CouchbaseLiteSwift`::-[CBLWebSocket receivedBytes:length:](self=0x0000000108612710, _cmd=<unavailable>, bytes=0x0000000107268000, length=18446744073709551615) at CBLWebSocket.mm:517 [opt]
    frame #12: 0x00000001012f7638 CouchbaseLiteSwift`::-[CBLWebSocket doRead](self=0x0000000108612710, _cmd=<unavailable>) at CBLWebSocket.mm:0 [opt]
    frame #13: 0x00000001012f78b0 CouchbaseLiteSwift`::-[CBLWebSocket stream:handleEvent:](self=0x0000000108612710, _cmd=<unavailable>, stream=<unavailable>, eventCode=<unavailable>) at CBLWebSocket.mm:683 [opt]
    frame #14: 0x000000018260bb34 CoreFoundation`_signalEventSync + 212
    frame #15: 0x0000000182689ea4 CoreFoundation`___signalEventQueue_block_invoke + 24
    frame #16: 0x00000001032f51dc libdispatch.dylib`_dispatch_call_block_and_release + 24
    frame #17: 0x00000001032f519c libdispatch.dylib`_dispatch_client_callout + 16
    frame #18: 0x0000000103303dfc libdispatch.dylib`_dispatch_queue_serial_drain + 768
    frame #19: 0x00000001032f86ac libdispatch.dylib`_dispatch_queue_invoke + 328
    frame #20: 0x0000000103304d54 libdispatch.dylib`_dispatch_root_queue_drain_deferred_wlh + 352
    frame #21: 0x000000010330be38 libdispatch.dylib`_dispatch_workloop_worker_thread + 676
    frame #22: 0x00000001822f7e70 libsystem_pthread.dylib`_pthread_wqthread + 860
    frame #23: 0x00000001822f7b08 libsystem_pthread.dylib`start_wqthread + 4

The bytes read after stream error is wrong DoRead read 18446744073709551615 bytes. Most likely this is caused by casting a negative number to an unsigned (size_t) value in this line.

@pasin

This comment has been minimized.

Contributor

pasin commented Aug 28, 2018

I couldn't figure out what causes the crash from the 1st crash. We forgot to capture CBL Log and exception. So we will need to try to reproduce the issue.

@sridevi-15

This comment has been minimized.

sridevi-15 commented Aug 28, 2018

Sure, we can sit tomorrow and let's try it again on the device I tested today. Btw, isn't not reproducible on your device?

@snej

This comment has been minimized.

Member

snej commented Aug 28, 2018

c4socket_received's implementation doesn't have a try/catch block, so throwing an exception causes an abort/crash ... we should fix that in LiteCore.

@djpongh djpongh added the known-issue label Aug 28, 2018

pasin added a commit that referenced this issue Aug 28, 2018

Fix casting nagative to unsigned value when reading bytes from NSInpu…
…tStream

When an error occurred from reading an NSInputStream, a nagative value will be retured. Casting the value to size_t which is an usigned type will result to a very large number and cause bad_alloc when trying to allocate memory for the invalid bytes read.

#2196

@djpongh djpongh added the icebox label Aug 28, 2018

@pasin

This comment has been minimized.

Contributor

pasin commented Aug 29, 2018

I and @sridevi-15 have tried to reproduce the 1st crash but unfortunately we couldn't reproduce it today. I have been able to reproduce the 2nd crashes a few times today when trying to bring the app foreground / background several time in a bad network environment.

@pasin

This comment has been minimized.

Contributor

pasin commented Aug 29, 2018

I push the casting negative value to unsigned value fix to the master branch. The fix will not go into 2.1.

@ritamcouchbase

This comment has been minimized.

ritamcouchbase commented Aug 29, 2018

@pasin - Should we release note this as part of 2.1 for now.

@pasin

This comment has been minimized.

Contributor

pasin commented Aug 29, 2018

Yes, that is what @djpongh has communicated to me. We may have a minor release (e.g. 2.1.1) to fix replication crash.

@rajagp

This comment has been minimized.

Contributor

rajagp commented Aug 29, 2018

Pasin’s understanding is correct

@pasin pasin changed the title from crash with wifi disabled and bad network on todo app to Crash with wifi disabled and bad network on todo app Aug 29, 2018

@djpongh djpongh modified the milestones: 2.1.0, Iridium Sep 4, 2018

@djpongh djpongh added the P1: high label Sep 4, 2018

@djpongh djpongh modified the milestones: Iridium, 2.1.1 Sep 4, 2018

@djpongh djpongh added backlog and removed icebox labels Sep 4, 2018

@djpongh djpongh modified the milestones: 2.1.1, 2.1.2 Sep 12, 2018

pasin added a commit that referenced this issue Sep 20, 2018

Fix casting nagative to unsigned value when reading bytes from NSInpu…
…tStream

When an error occurred from reading an NSInputStream, a nagative value will be retured. Casting the value to size_t which is an usigned type will result to a very large number and cause bad_alloc when trying to allocate memory for the invalid bytes read.

#2196

@djpongh djpongh added ready and removed backlog labels Sep 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment