Skip to content

App crashes with "Task should be completed." or sends saveEventually requests twice after Parse.setServer #1920

Closed

Description

@mtrezza

New Issue Checklist

Issue Description

Since #1708 (2.0.3), +[Parse setServer:] re-initializes Parse with a new ParseManager, which creates its own eventually queue. The previous manager's eventually queue (PFCommandCache, or PFPinningEventuallyQueue with the local datastore) is not paused or terminated. It stays alive because its dispatch source event handler retains it, and it remains a PFReachability listener. Both queues read the same pending commands from the same command cache directory or local datastore. Parse/Parse/Internal/PFCommandCache.h says there should only be one instance, "because multiple instances would be running separate threads trying to read and execute the same commands."

When connectivity returns while saveEventually commands are pending, both queues run them:

  • If the previous ParseManager was deallocated, the old queue's weak dataSource is nil, so -[PFEventuallyQueue _runCommand:withIdentifier:] returns nil. PFConsistencyAssert(resultTask.completed, ...) in -_didFinishRunningCommand:withIdentifier:resultTask: then raises NSInternalInconsistencyException ("Task should be completed.") on the queue's processing queue, which terminates the app.
  • If the previous ParseManager is still alive, both queues send the command. A Cloud Code call before setServer: is one thing that keeps it alive, because PFCloudCodeController holds its data source strongly. Without the local datastore, the same request is sent twice. With the local datastore, the old queue sends an empty save (POST classes/<className> with no fields), because only the new queue holds the save's operation set in memory.

Nothing stops the old queue, so this applies until the app is terminated. #913 (2016) reported the same exception with the same stack, before setServer: existed.

Not verified:

  • The duplicate goes to the previous server if the previous manager's command runner existed before setServer:. The old queue sends its duplicate through that runner, which keeps the server URL it was created with.
  • The old queue also starts a run when it finishes waiting to retry a command after a temporary error, not only when connectivity returns.
  • Each further setServer: call adds another queue.

Found while investigating #1917.

Steps to reproduce

Reproduced in a unit test on master (iOS 26.5 simulator, Xcode 27.1) with mock command runners. Connectivity changes are simulated through PFReachability.

  1. Initialize Parse, with or without local datastore.
  2. Call +[Parse setServer:] with another URL.
  3. Lose connectivity.
  4. Call saveEventually on a new object.
  5. Regain connectivity.

Losing connectivity before step 2 gives the same result. With local datastore, only that order was tested. To keep the previous manager alive, call a Cloud Code function before step 2.

Actual Outcome

Previous manager deallocated (the case in the test without the Cloud Code call):

  • The new queue sends the request and the old queue raises NSInternalInconsistencyException: Task should be completed., with and without local datastore.
  • XCTest records the exception as a test failure. When the uncaught exception handler only logs and returns, like the default handler in an app, the test host aborts with SIGABRT (tested without local datastore).

Previous manager alive:

  • Without local datastore, the old and the new command runner both send POST classes/Yolo with the same body.
  • With local datastore, the new runner sends POST classes/Yolo with the object's field, and the old runner sends POST classes/Yolo with no fields.

Without setServer:, a pending command is sent once.

Expected Outcome

After setServer:, only one eventually queue processes pending commands. Each command is sent once and no exception is raised.

Environment

Client

  • Parse ObjC SDK version: 7.0.0 (master)

Server

  • Parse Server version: not applicable
  • Operating system: not applicable
  • Local or remote host: not applicable

Database

  • System (MongoDB or Postgres): not applicable
  • Database version: not applicable
  • Local or remote host: not applicable

Logs

Stack of the crashing thread (com.parse.PFCommandCache.processing queue, EXC_CRASH (SIGABRT)):

+[NSException raise:format:]
-[PFEventuallyQueue _didFinishRunningCommand:withIdentifier:resultTask:]
-[PFCommandCache _didFinishRunningCommand:withIdentifier:resultTask:]
-[PFEventuallyQueue _runCommandsWithRetriesCount:]
-[PFEventuallyQueue _runCommands]
__26-[PFEventuallyQueue start]_block_invoke

With local datastore, the exception is raised through -[PFPinningEventuallyQueue _didFinishRunningCommand:withIdentifier:resultTask:] instead of PFCommandCache.

Activity

  1. parse-github-assistant commented on Oct 22, 2026

    @parse-github-assistant

    🚀 Thanks for opening this issue!

    ℹ️ You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

  2. parseplatformorg commented on Oct 23, 2026

    @parseplatformorg
    Contributor

    🎉 This change has been released in version 7.0.2

  3. added
    state:released
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:released

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions