Skip to content

chore(navigation-app): stop cancelling the pending route future when a new destination is picked - #1094

Merged
kikoso merged 1 commit into
mainfrom
fix/navigation-sample-cancel-crash
Nov 24, 2026
Merged

kikoso merged 1 commit into
mainfrom
fix/navigation-sample-cancel-crash

Conversation

@kikoso

@kikoso kikoso commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

The Navigation SDK sample app added in #1061 crashes when a new destination is picked while the previous route is still being calculated:

java.lang.IllegalStateException: Task was cancelled.
    at com.google.android.libraries.navigation.internal.za.a.a(PG:1)
    at com.google.android.libraries.navigation.internal.agl.bd.run(PG:4)
    at android.os.Handler.handleCallback(Handler.java:942)

navigateToLatLng and navigateToPlace cancel the previous navigationJob, and startNavigationToWaypoint reacted to that by calling routeStatusFuture.cancel(true) on the pending setDestination future. The Navigation SDK then throws when it delivers the cancelled future on the main thread, which kills the app.

This removes the cancel(true) call. A new setDestination() (or clearDestinations() from stopNavigation()) already replaces the pending route in the SDK, and the result listener already ignores late results once its coroutine is no longer active. The existing superseded-destination test now checks that the future is never cancelled.

Only the sample app changes, so it is marked as a chore to avoid a library release.

Testing

  • :navigation-app:testDebugUnitTest: 17 tests, all passing.
  • :navigation-app:lintDebug: passing.
  • Pixel 4 (Android 13), with Wi-Fi and mobile data turned off so the first route request stays pending, then a second long-press on the map 3 seconds later:
    • main: crashed with Task was cancelled in 2 of 2 runs.
    • This branch: no crash in 3 of 3 runs. The second request fails with a network error snackbar, as expected while offline.
  • With the network on, rapid repeated long-presses start guidance to the last destination picked, with no crash.

@googlemaps-bot

Copy link
Copy Markdown
Contributor

Coverage (instrumentation tests)

Overall Project 46.12% 🍏

There is no coverage information present for the Files changed

@github-actions

Copy link
Copy Markdown

Coverage (unit tests)

Compared against 536cec6 on main (#1061).

Module Line % Change Branch % Change
maps-compose 45.82% no change 15.23% no change
maps-compose-utils 26.29% no change 12.70% no change
maps-compose-widgets 3.87% no change 0.00% no change
TOTAL 38.93% no change 14.22% no change

Line and branch coverage from unit test reports. History is recorded on the coverage-history branch after each merge to main.

@dkhawk dkhawk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Clean fix and clear explanation of why the Navigation SDK future shouldn't be cancelled on coroutine cancellation.

@kikoso
kikoso merged commit b418c7b into main Nov 24, 2026
14 checks passed
@kikoso
kikoso deleted the fix/navigation-sample-cancel-crash branch November 24, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants