Skip to content

fix: App crashes with "Task should be completed." or sends saveEventually requests twice after Parse.setServer - #1934

Merged
mtrezza merged 2 commits into
parse-community:masterfrom
mtrezza:fix/set-server-eventually-queue
Oct 23, 2026
Merged

mtrezza merged 2 commits into
parse-community:masterfrom
mtrezza:fix/set-server-eventually-queue

Conversation

@mtrezza

@mtrezza mtrezza commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

New Pull Request Checklist

Issue Description

Since #1708 (2.0.3), +[Parse setServer:] re-initializes Parse with a new ParseManager, and the eventually queue of the previous manager keeps running on the same pending commands. When connectivity returns while saveEventually commands are pending, both queues run them. The app crashes with NSInternalInconsistencyException ("Task should be completed.") if the previous manager was deallocated, or sends the request twice. With the local datastore, the second request is an empty save.

Closes: #1920

Approach

setServer: no longer re-initializes Parse. It sets the new server URL in the configuration and the command runner of the current manager, so there is only one eventually queue. #1528 said that the SDK must be re-initialized because the server URL is stored in many controllers. Only the command runner and its request constructor hold it, and the constructor reads it for every request. PFPushController, the only controller that keeps a command runner, keeps the same instance. The runner is changed, not replaced, because releasing a runner cancels the requests it is sending, and the eventually queue removes a cancelled command as finished.

  • Requests that are already being sent complete against the previous server URL. All other requests go to the new server URL, including retries and pending saveEventually and deleteEventually commands queued before setServer:.
  • setServer: also makes the eventually queue retry its pending commands right away. Otherwise a command that waits to be retried after a temporary error, which is likely when the previous server fails, would wait up to 10 minutes (the retry interval) before it goes to the new server.
  • setServer: no longer posts PFParseInitializeDidCompleteNotification, which is documented as being for testing, and no longer calls parseDidInitializeWithApplicationId:clientKey: of Parse modules.
  • Re-initializing also lost state that is now kept:
    • registered authentication delegates; logging in anonymously after setServer: raised an exception, because the delegate was registered with the previous manager
    • the default ACL and the automatic user
    • purchase observers
    • the object identity of the local datastore and the mappings of local IDs to object IDs
  • Batch requests that are in progress, for example of saveAll, keep the path of the previous server URL. The setServer: docs now say that they fail if the new server URL has a different path.

The 7 new tests in ParseSetupUnitTests fail on master. They cover:

  • the server URL of the command runner and of the requests it creates
  • a pending command being sent once, with and without the local datastore, queued before and after setServer:
  • the retry of a command that waits to be retried or that fails while the server is set

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)

Summary by CodeRabbit

  • New Features
    • Change the server URL without reinitializing Parse or losing the current client configuration and state.
    • Requests already in progress continue using the previous URL; subsequent requests use the new URL.
    • Pending queued commands are retried immediately against the new server. The retry request does not wait for those commands to finish.
  • Documentation
    • Clarified how server changes affect retries, delayed commands, file URLs, and in-progress batch requests, including a warning about server path differences.

@parse-github-assistant

Copy link
Copy Markdown

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 3332def2-f4b3-4ac7-b47e-b77bf00ebce7
📥 Commits

Reviewing files that changed from the base of the PR and between 4c76f05 and 52bdb9e.

📒 Files selected for processing: 11
  • Parse/Parse/Internal/Commands/CommandRunner/PFCommandRunning.h
  • Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.h
  • Parse/Parse/Internal/Commands/CommandRunner/URLSession/PFURLSessionCommandRunner.m
  • Parse/Parse/Internal/PFEventuallyQueue.h
  • Parse/Parse/Internal/PFEventuallyQueue.m
  • Parse/Parse/Internal/PFEventuallyQueue_Private.h
  • Parse/Parse/Internal/ParseManager.h
  • Parse/Parse/Internal/ParseManager.m
  • Parse/Parse/Source/Parse.h
  • Parse/Parse/Source/Parse.m
  • Parse/Tests/Unit/ParseSetupUnitTests.m

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Parse.setServer: now updates the active ParseManager without reinitializing it. The command runner uses the updated server URL for newly created requests. The eventually queue can retry pending commands immediately after a server change.

Changes: Active server switching

Layer / File(s) Summary
Writable request URL
Parse/Parse/Internal/Commands/CommandRunner/PFCommandRunning.h, Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.h, Parse/Parse/Internal/Commands/CommandRunner/URLSession/PFURLSessionCommandRunner.m
The runner’s serverURL is writable and forwards reads and writes to the request constructor.
Immediate queue retries
Parse/Parse/Internal/PFEventuallyQueue.h, Parse/Parse/Internal/PFEventuallyQueue_Private.h, Parse/Parse/Internal/PFEventuallyQueue.m
retryPendingCommands requests another command run and can end the current retry wait early.
In-place server updates and validation
Parse/Parse/Internal/ParseManager.h, Parse/Parse/Internal/ParseManager.m, Parse/Parse/Source/Parse.h, Parse/Parse/Source/Parse.m, Parse/Tests/Unit/ParseSetupUnitTests.m
When Parse is initialized, setServer: updates the active manager and requests an asynchronous queue retry. Tests cover pending commands, retry waits, in-flight commands, and preservation of the manager and queue.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Parse
  participant ParseManager
  participant PFURLSessionCommandRunner
  participant PFCommandURLRequestConstructor
  participant PFEventuallyQueue
  Parse->>ParseManager: setServer(server)
  ParseManager->>PFURLSessionCommandRunner: set serverURL
  PFURLSessionCommandRunner->>PFCommandURLRequestConstructor: update serverURL
  ParseManager->>PFEventuallyQueue: retryPendingCommands()
Loading
Merge Risk: ⚪ Minimal · up to 52bdb

No concrete issue remains that should block merging after normal checks.

Pre-merge checks: Passed 6 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 6 files. (5 skipped: 5 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 6 passed
Check name Status Explanation
Title check Passed The title uses the required "fix:" prefix and capitalizes the first letter after it ("App"). It describes the main change: the fix for crashes and duplicate saveEventually requests after Parse.setServ…
Description check Passed The description follows the template. It has the checklist with both boxes checked, an Issue Description that links #1920, an Approach section that explains the design and the reasons for it, and TODO…
Linked Issues check Passed Issue #1920 requires one eventually queue after +[Parse setServer:], one send per pending command, and no NSInternalInconsistencyException. Parse.m now updates the active ParseManager in place…
Out of Scope Changes check Passed The changes stay within the setServer: queue-consistency scope of issue #1920. The command-runner URL update, retry control, documentation, and focused tests support the single-queue and single-send…
Security Check Passed No security vulnerability pattern is introduced by the reviewed changes. The PR only makes the existing, application-controlled server URL mutable and validates it through the existing `ParseClientCon…
Engage In Review Feedback Passed No review feedback comments were returned, and the current review produced zero actionable findings. Therefore, there is no feedback that the user ignored or resolved without prior engagement.
Full details: Title check

Explanation

The title uses the required "fix:" prefix and capitalizes the first letter after it ("App"). It describes the main change: the fix for crashes and duplicate saveEventually requests after Parse.setServer. The changeset makes setServer: update the existing manager and command runner instead of reinitializing, and it adds retryPendingCommands, which matches the title's subject. Title length is 114 characters, which is long but does not violate the stated requirements.

Full details: Description check

Explanation

The description follows the template. It has the checklist with both boxes checked, an Issue Description that links #1920, an Approach section that explains the design and the reasons for it, and TODOs with both items checked. The Issue Description gives the "Closes: #1920" reference, so the template placeholder FILL_THIS_OUT is not present. The description covers the required sections in enough detail for review.

Full details: Linked Issues check

Explanation

Issue #1920 requires one eventually queue after +[Parse setServer:], one send per pending command, and no NSInternalInconsistencyException. Parse.m now updates the active ParseManager in place. ParseManager.m updates the existing configuration and command runner, then requests an immediate retry. The new ParseSetupUnitTests cover pending commands queued before and after setServer:, with and without the local datastore, plus retry-waiting and running commands. They assert one command, preserved manager and queue identity, and successful completion.

Full details: Out of Scope Changes check

Explanation

The changes stay within the setServer: queue-consistency scope of issue #1920. The command-runner URL update, retry control, documentation, and focused tests support the single-queue and single-send behavior. No unrelated product behavior is established by the reviewed changes.

Full details: Security Check

Explanation

No security vulnerability pattern is introduced by the reviewed changes. The PR only makes the existing, application-controlled server URL mutable and validates it through the existing ParseClientConfiguration setter before updating the command runner (Parse/Parse/Internal/ParseManager.m:165-174; Parse/Parse/Source/ParseClientConfiguration.m:71-76). Request construction still uses the configured URL and existing URL constructor (PFCommandURLRequestConstructor.m:48-58). The remaining production changes control retry scheduling and preserve one queue; they do not add credential logging, shell execution, unsafe deserialization, storage exposure, or new trust-boundary handling. The added tests also verify invalid URLs do not replace the current URL and that pending commands are sent once.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 6 files. (5 skipped: 5 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.30942% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.73%. Comparing base (dd05d41) to head (52bdb9e).
⚠️ Report is 99 commits behind head on master.

Files with missing lines Patch % Lines
Parse/Tests/Unit/ParseSetupUnitTests.m 97.90% 4 Missing ⚠️
Parse/Parse/Source/Parse.m 66.66% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1934       +/-   ##
===========================================
+ Coverage   64.24%   85.73%   +21.49%     
===========================================
  Files         201      282       +81     
  Lines       23233    31187     +7954     
===========================================
+ Hits        14926    26739    +11813     
+ Misses       8307     4448     -3859     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mtrezza
mtrezza merged commit 955b230 into parse-community:master Oct 23, 2026
30 of 31 checks passed
parseplatformorg pushed a commit that referenced this pull request Oct 23, 2026
## [7.0.2](7.0.1...7.0.2) (2026-10-23)

### Bug Fixes

* App crashes with "Task should be completed." or sends `saveEventually` requests twice after `Parse.setServer` ([#1934](#1934)) ([955b230](955b230))
@parseplatformorg

Copy link
Copy Markdown
Contributor

🎉 This change has been released in version 7.0.2

@parseplatformorg parseplatformorg added the state:released Released as stable version label Oct 23, 2026
@mtrezza
mtrezza deleted the fix/set-server-eventually-queue branch October 23, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:released Released as stable version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants