Skip to content
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

Continuous WebSocket puller crashes when receiving changes after changing user's password #1140

Closed
pasin opened this issue Feb 24, 2016 · 2 comments
Assignees
Milestone

Comments

@pasin
Copy link
Contributor

pasin commented Feb 24, 2016

This is observed from #1138.

10:57:23.728‖ ChangeTrackerVerbose: CBLWebSocketChangeTracker[0x6110000ca980 db]: Got a message: <54cd3112 c4200846 e1bbd8ef 0c28281c 87d59f03 6cb14d26 778f4552 a4ffdebc 87ca4d81 6457eb2b 25846a80 69785dd5 95bf82d1 5efd517e f8ef883f ded36df2 940d0d94 53555ba8 db425037 2fe77e5d 000000ff ff>
10:57:23.728‖ ChangeTrackerVerbose: CBLWebSocketChangeTracker[0x6110000ca980 db]: read 108 bytes
10:57:23.728‖ SyncVerbose: CBLRestPuller[http://10.0.1.7:4984/db]: postProgressChanged (0/1, active=0 (batch=0, net=0), online=1)
10:57:23.728‖ SyncVerbose: CBLRestPuller[http://10.0.1.7:4984/db]: Received #4 {eef19586df4a402ae10792d2951b4e73 #1-96f98c1c42958e0fc5553a598dea0689}
10:57:23.729‖ Sync: CBLRestPuller[http://10.0.1.7:4984/db] Progress: set active = 1
10:57:23.729‖ SyncVerbose: CBLRestPuller[http://10.0.1.7:4984/db]: postProgressChanged (0/1, active=1 (batch=1, net=0), online=1)
10:57:23.729‖ ChangeTracker: CBLWebSocketChangeTracker[0x6110000ca980 db]: RESUME WebSocket
10:57:23.729| Sync: CBLReplication[from http://10.0.1.7:4984/db]: active, progress = 0 / 1, err: (null)
10:57:23.729‖ ChangeTrackerVerbose: CBLWebSocketChangeTracker[0x6110000ca980 db]: Got a message: 
2016-02-24 10:57:23.729 CBL Test[68259:3525395] < PULL 0 / 1 : (null)
10:57:23.729‖ SyncVerbose: *** CBLRestPuller[http://10.0.1.7:4984/db]: BEGIN processInbox (1 sequences)
10:57:23.729‖ SyncVerbose: CBLRestPuller[http://10.0.1.7:4984/db]: Looking up (
    "{eef19586df4a402ae10792d2951b4e73 #1-96f98c1c42958e0fc5553a598dea0689}"
)
10:57:23.730‖ SyncVerbose: CBLRestPuller[http://10.0.1.7:4984/db] queuing remote revisions (
    "{eef19586df4a402ae10792d2951b4e73 #1-96f98c1c42958e0fc5553a598dea0689}"
)
10:57:23.730‖ Sync: CBLRestPuller[http://10.0.1.7:4984/db] queued 1 remote revisions from seq=4 (1 in bulk, 0 individually)
10:57:23.730‖ SyncVerbose: CBLRestPuller[http://10.0.1.7:4984/db]: GET eef19586df4a402ae10792d2951b4e73?rev=1-96f98c1c42958e0fc5553a598dea0689&revs=true&attachments=true
10:57:23.731‖ SyncVerbose: *** CBLRestPuller[http://10.0.1.7:4984/db]: END processInbox (lastSequence=2)
10:57:23.830‖ CBLMultipartDownloader[/db/eef19586df4a402ae10792d2951b4e73]: Got error Error Domain=CBLHTTP Code=401 "401 unauthorized" UserInfo={NSURL=http://10.0.1.7:4984/db/eef19586df4a402ae10792d2951b4e73?rev=1-96f98c1c42958e0fc5553a598dea0689&revs=true&attachments=true, NSLocalizedFailureReason=unauthorized, NSLocalizedDescription=401 unauthorized}
10:57:23.830‖ Sync: CBLRestPuller[http://10.0.1.7:4984/db] Progress: set error = 401 unauthorized
10:57:23.830‖ Sync: CBLRestPuller[http://10.0.1.7:4984/db] STOPPING...
10:57:23.830‖ ChangeTracker: CBLWebSocketChangeTracker[0x6110000ca980 db]: stop
10:57:23.830‖ ChangeTracker: CBLWebSocketChangeTracker[0x6110000ca980 db]: stop
10:57:23.831‖ Sync: Stopping 1 remote requests
10:57:23.831‖ Sync: CBLRestPuller[http://10.0.1.7:4984/db] Progress: set active = 0
10:57:23.831‖ SyncVerbose: CBLRestPuller[http://10.0.1.7:4984/db]: postProgressChanged (0/1, active=0 (batch=0, net=0), online=1)
10:57:23.831‖ Sync: CBLRestPuller[http://10.0.1.7:4984/db] STOPPED
10:57:23.831‖ Replication: CBLRestPuller[http://10.0.1.7:4984/db] took 34.491 sec; error=Error Domain=CBLHTTP Code=401 "401 unauthorized" UserInfo={NSURL=http://10.0.1.7:4984/db/eef19586df4a402ae10792d2951b4e73?rev=1-96f98c1c42958e0fc5553a598dea0689&revs=true&attachments=true, NSLocalizedFailureReason=unauthorized, NSLocalizedDescription=401 unauthorized}
2016-02-24 10:57:23.831 CBL Test[68259:3525476] *** ASSERTION FAILED: _asyncTaskCount >= 0
2016-02-24 10:57:23.831 CBL Test[68259:3525476] *** Assertion failure in -[CBLRestReplicator asyncTasksFinished:](), /Users/pasin/Git/couchbase/couchbase-lite-ios/Source/CBLRestReplicator.m:527
2016-02-24 10:57:23.845 CBL Test[68259:3525476] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_asyncTaskCount >= 0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010f1d6e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010ec4fdeb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010f1d6cca +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x000000010e6745a2 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 169
    4   CBL Test                            0x000000010b173ba5 _AssertFailed + 1557
    5   CBL Test                            0x000000010af9d9e6 -[CBLRestReplicator asyncTasksFinished:] + 310
    6   CBL Test                            0x000000010afb3fec __36-[CBLRestPuller pullRemoteRevision:]_block_invoke + 2412
    7   CBL Test                            0x000000010afff6c4 -[CBLRemoteRequest respondWithResult:error:] + 964
    8   CBL Test                            0x000000010b004b39 -[CBLRemoteRequest connection:didFailWithError:] + 1289
    9   CBL Test                            0x000000010afffe12 -[CBLRemoteRequest cancelWithStatus:] + 402
    10  CBL Test                            0x000000010b003add -[CBLRemoteRequest connection:didReceiveResponse:] + 2525
    11  CBL Test                            0x000000010b025bf5 -[CBLMultipartDownloader connection:didReceiveResponse:] + 2181
    12  CFNetwork                           0x000000010cd4ba88 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
    13  CFNetwork                           0x000000010cd4ba2c -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
    14  CFNetwork                           0x000000010cd4bb81 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
    15  CFNetwork                           0x000000010cd20466 _ZL34_NSURLConnectionDidReceiveResponseP16_CFURLConnectionP14_CFURLResponsePKv + 82
    16  CFNetwork                           0x000000010cbb6ff9 ___ZN27URLConnectionClient_Classic28_delegate_didReceiveResponseEP14_CFURLResponse_block_invoke + 114
    17  CFNetwork                           0x000000010cca7965 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 100
    18  libdispatch.dylib                   0x000000010f6814a7 _dispatch_client_callout + 8
    19  libdispatch.dylib                   0x000000010f668223 _dispatch_block_invoke + 408
    20  CFNetwork                           0x000000010cba61ac _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 24
    21  CoreFoundation                      0x000000010f0d5ee4 CFArrayApplyFunction + 68
    22  CFNetwork                           0x000000010cba60a5 _ZN19RunloopBlockContext7performEv + 137
    23  CFNetwork                           0x000000010cba5f5e _ZN17MultiplexerSource7performEv + 282
    24  CFNetwork                           0x000000010cba5d80 _ZN17MultiplexerSource8_performEPv + 72
    25  CoreFoundation                      0x000000010f102a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    26  CoreFoundation                      0x000000010f0f895c __CFRunLoopDoSources0 + 556
    27  CoreFoundation                      0x000000010f0f7e13 __CFRunLoopRun + 867
    28  CoreFoundation                      0x000000010f0f7828 CFRunLoopRunSpecific + 488
    29  Foundation                          0x000000010e6142f1 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 267
    30  CBL Test                            0x000000010af8d5de -[CBL_RunLoopServer runServerThread] + 1054
    31  Foundation                          0x000000010e6b1dfb __NSThread__start__ + 1198
    32  libsystem_pthread.dylib             0x000000010f9b4c13 _pthread_body + 131
    33  libsystem_pthread.dylib             0x000000010f9b4b90 _pthread_body + 0
    34  libsystem_pthread.dylib             0x000000010f9b2375 thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

  • Version: Master (a72c942)
  • Client OS: iPhone 6 Simulator
  • Server: SGW 1.2
@pasin
Copy link
Contributor Author

pasin commented Feb 24, 2016

The cause of the crash is because CBLMultipartDownloader's onCompletion block got called twice from the connection fail itself and from RemoteRequest's stop (as a result of setting CBLRestReplicator.error).

1st call:

thread #8: tid = 0x383b64, 0x00000001027d188a CBL Test`__36-[CBLRestPuller pullRemoteRevision:]_block_invoke(.block_descriptor=<unavailable>, result=0x0000000000000000, error=domain: @"CBLHTTP" - code: 401) + 522 at CBLRestPuller.m:440, name = 'CouchbaseLite', stop reason = breakpoint 1.1
  * frame #0: 0x00000001027d188a CBL Test`__36-[CBLRestPuller pullRemoteRevision:]_block_invoke(.block_descriptor=<unavailable>, result=0x0000000000000000, error=domain: @"CBLHTTP" - code: 401) + 522 at CBLRestPuller.m:440
    frame #1: 0x000000010281d6c4 CBL Test`-[CBLRemoteRequest respondWithResult:error:](self=0x000060b00006d280, _cmd="respondWithResult:error:", result=0x0000000000000000, error=domain: @"CBLHTTP" - code: 401) + 964 at CBLRemoteRequest.m:181
    frame #2: 0x0000000102822b39 CBL Test`-[CBLRemoteRequest connection:didFailWithError:](self=0x000060b00006d280, _cmd="connection:didFailWithError:", connection=0x000060200004f5d0, error=domain: @"CBLHTTP" - code: 401) + 1289 at CBLRemoteRequest.m:450
    frame #3: 0x000000010281de12 CBL Test`-[CBLRemoteRequest cancelWithStatus:](self=0x000060b00006d280, _cmd="cancelWithStatus:", status=401) + 402 at CBLRemoteRequest.m:212
    frame #4: 0x0000000102821add CBL Test`-[CBLRemoteRequest connection:didReceiveResponse:](self=0x000060b00006d280, _cmd="connection:didReceiveResponse:", connection=0x000060200004f5d0, response=0x00006030001196e0) + 2525 at CBLRemoteRequest.m:410
    frame #5: 0x0000000102843bf5 CBL Test`-[CBLMultipartDownloader connection:didReceiveResponse:](self=0x000060b00006d280, _cmd="connection:didReceiveResponse:", connection=0x000060200004f5d0, response=0x00006030001196e0) + 2181 at CBLMultipartDownloader.m:87
    frame #6: 0x0000000104569a88 CFNetwork`__65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
    frame #7: 0x0000000104569a2c CFNetwork`-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
    frame #8: 0x0000000104569b81 CFNetwork`-[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
    frame #9: 0x000000010453e466 CFNetwork`_NSURLConnectionDidReceiveResponse(_CFURLConnection*, _CFURLResponse*, void const*) + 82

2nd call:

* thread #8: tid = 0x383b64, 0x00000001027d188a CBL Test`__36-[CBLRestPuller pullRemoteRevision:]_block_invoke(.block_descriptor=<unavailable>, result=0x0000000000000000, error=domain: @"NSURLErrorDomain" - code: 18446744073709550617) + 522 at CBLRestPuller.m:440, name = 'CouchbaseLite', stop reason = breakpoint 1.1
  * frame #0: 0x00000001027d188a CBL Test`__36-[CBLRestPuller pullRemoteRevision:]_block_invoke(.block_descriptor=<unavailable>, result=0x0000000000000000, error=domain: @"NSURLErrorDomain" - code: 18446744073709550617) + 522 at CBLRestPuller.m:440
    frame #1: 0x000000010281d6c4 CBL Test`-[CBLRemoteRequest respondWithResult:error:](self=0x000060b00006d280, _cmd="respondWithResult:error:", result=0x0000000000000000, error=domain: @"NSURLErrorDomain" - code: 18446744073709550617) + 964 at CBLRemoteRequest.m:181
    frame #2: 0x000000010281dbac CBL Test`-[CBLRemoteRequest stop](self=0x000060b00006d280, _cmd="stop") + 876 at CBLRemoteRequest.m:202
    frame #3: 0x00000001069354a0 CoreFoundation`-[NSArray makeObjectsPerformSelector:] + 224
    frame #4: 0x00000001027c1791 CBL Test`-[CBLRestReplicator stopRemoteRequests](self=0x00006120000f37c0, _cmd="stopRemoteRequests") + 785 at CBLRestReplicator.m:730
    frame #5: 0x00000001027b8af7 CBL Test`-[CBLRestReplicator stop](self=0x00006120000f37c0, _cmd="stop") + 295 at CBLRestReplicator.m:318
    frame #6: 0x00000001027ca8bc CBL Test`-[CBLRestPuller stop](self=0x00006120000f37c0, _cmd="stop") + 1356 at CBLRestPuller.m:162
    frame #7: 0x00000001027b6a37 CBL Test`-[CBLRestReplicator setError:](self=0x00006120000f37c0, _cmd="setError:", error=domain: @"CBLHTTP" - code: 401) + 1223 at CBLRestReplicator.m:236
    frame #8: 0x00000001027d1c4d CBL Test`__36-[CBLRestPuller pullRemoteRevision:]_block_invoke(.block_descriptor=<unavailable>, result=0x0000000000000000, error=domain: @"CBLHTTP" - code: 401) + 1485 at CBLRestPuller.m:450
    frame #9: 0x000000010281d6c4 CBL Test`-[CBLRemoteRequest respondWithResult:error:](self=0x000060b00006d280, _cmd="respondWithResult:error:", result=0x0000000000000000, error=domain: @"CBLHTTP" - code: 401) + 964 at CBLRemoteRequest.m:181
    frame #10: 0x0000000102822b39 CBL Test`-[CBLRemoteRequest connection:didFailWithError:](self=0x000060b00006d280, _cmd="connection:didFailWithError:", connection=0x000060200004f5d0, error=domain: @"CBLHTTP" - code: 401) + 1289 at CBLRemoteRequest.m:450
    frame #11: 0x000000010281de12 CBL Test`-[CBLRemoteRequest cancelWithStatus:](self=0x000060b00006d280, _cmd="cancelWithStatus:", status=401) + 402 at CBLRemoteRequest.m:212
    frame #12: 0x0000000102821add CBL Test`-[CBLRemoteRequest connection:didReceiveResponse:](self=0x000060b00006d280, _cmd="connection:didReceiveResponse:", connection=0x000060200004f5d0, response=0x00006030001196e0) + 2525 at CBLRemoteRequest.m:410
    frame #13: 0x0000000102843bf5 CBL Test`-[CBLMultipartDownloader connection:didReceiveResponse:](self=0x000060b00006d280, _cmd="connection:didReceiveResponse:", connection=0x000060200004f5d0, response=0x00006030001196e0) + 2181 at CBLMultipartDownloader.m:87
    frame #14: 0x0000000104569a88 CFNetwork`__65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 69
    frame #15: 0x0000000104569a2c CFNetwork`-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
    frame #16: 0x0000000104569b81 CFNetwork`-[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 48
    frame #17: 0x000000010453e466 CFNetwork`_NSURLConnectionDidReceiveResponse(_CFURLConnection*, _CFURLResponse*, void const*) + 82

@pasin pasin self-assigned this Feb 24, 2016
@pasin
Copy link
Contributor Author

pasin commented Feb 24, 2016

Seem like the dev branch has slightly different implementation that doesn't maintain a list of requests anymore. However it still has the same crash that the completion block got called twice.

pasin added a commit that referenced this issue Feb 25, 2016
When there is a permanent error occurred, the onCompletion block could be called second time on stopping remote requests originated from setting error property value inside the onCompletion block. So change to break cycles before executing onCompletion block.

#1140
@pasin pasin added this to the 1.3 milestone Feb 25, 2016
pasin added a commit that referenced this issue Feb 25, 2016
Fixed CBLRemoteRequest's respondWithResult:error to check if onCompletion is nil or not before calling it.

#1140
snej added a commit that referenced this issue Feb 26, 2016
Fixed #1140 : CBLRemoteRequest onCompletion gets called twice
@snej snej closed this as completed Feb 26, 2016
@snej snej modified the milestones: 1.3, 1.2.1 Mar 3, 2016
pasin added a commit that referenced this issue Mar 4, 2016
…tion block

- Remove the remote request from the list first to prevent this block to be called second time when setting a permanent error to the error property.

- As the implementation on 1.2 and dev branch are diverted. This is a double fix of the dev branch's aeae2ea commit.

#1140
snej added a commit that referenced this issue Mar 4, 2016
…unt_crash

Fixed #1140 _asyncTaskCount double decreased in CBLMultipartDownloader completion block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants