Skip to content

[Due for payment 2026-11-18] [Sentry: APP-FR5] mapbox-gl telemetry calls errorCb after map teardown on the distance map #100845

Closed

Description

@mountiny

Sentry

Impact (snapshot at filing, 2026-09-10)

Sentry ID Users (last 14d) Users (total since first seen) Events First seen
APP-FR5 13 57 80 2026-06-19
  • Last seen: 2026-09-09 (ongoing)
  • Platform: web (standalone), seen on Edge and Chrome on Windows
  • App version(s): present across 9.4.62-4 through 9.4.73-3 — not a recent regression
  • Affected route(s): /create/submit/start/1/:transactionID/distance-new/distance-map
  • Affected view(s): distance-map
  • Mechanism: auto.browser.global_handlers.onunhandledrejection, level error
  • Roughly 1.4 events per affected user, so it fires once per exposure rather than in a loop

Error

TypeError: this.errorCb is not a function

Stack trace (top frames)

All frames are inside the bundled mapbox-gl distribution. There are no App frames.

node_modules/mapbox-gl/dist/mapbox-gl.js:19:10999
  ... skuToken:this.skuToken,userId:this.anonId},e=>{e?this.errorCb(e):o&&(this.success[o]=!0);},i));}
  remove(){this.errorCb=null;}

node_modules/mapbox-gl/dist/mapbox-gl.js:19:8868  (this.pendingRequest)
  this.pendingRequest=e.p(l,e=>{this.pendingRequest=null,o(e),this.saveEventData(),this.processRequests(r);});

node_modules/mapbox-gl/dist/mapbox-gl.js:11:24316

Suspected cause

This is a teardown race inside mapbox-gl's telemetry and turnstile event code, not in App logic.

The relevant object registers an error callback and fires a postEvent request. Its remove() method sets this.errorCb = null. When the map is removed while a telemetry request is still in flight, the request settles afterwards and the completion handler calls this.errorCb(e) on the now-null field, which throws. The throw happens inside a promise handler with no catch, so it surfaces as an unhandled rejection and Sentry records it as an unhandled error.

The trigger in App is leaving the distance map before the Mapbox telemetry request completes — for example tapping back or completing the step quickly on a slow connection. That matches the once-per-user event pattern.

Because the whole stack is third-party, the fix is not in App code. Options in order of preference:

  1. Bump mapbox-gl if a release since our pinned version fixes the null callback path. Check the upstream changelog and open issues for errorCb.
  2. If no upstream fix exists, delay map.remove() until in-flight telemetry settles, or disable Mapbox telemetry on this screen so the request is never issued.
  3. As a last resort, add a patch-package patch guarding the callback invocation.

Confirm the currently pinned mapbox-gl version before choosing.

Reproduction

  1. Open a new expense and choose Distance to reach /create/submit/start/1/:transactionID/distance-new/distance-map.
  2. Throttle the network in devtools so the Mapbox telemetry request stays in flight.
  3. Navigate away from the distance map immediately after it renders.
  4. Verify an unhandled this.errorCb is not a function rejection appears in the JS console.

Related

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. self-assigned this
    on Sep 10, 2026
  2. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Sep 10, 2026
  3. melvin-bot commented on Sep 10, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @Pujan92 (External)

  4. melvin-bot commented on Sep 10, 2026

    @melvin-bot

    Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

  5. MelvinBot commented on Sep 10, 2026

    @MelvinBot
    Contributor

    Proposal

    Two corrections to the issue body first, both verified in source:

    • The crashing object is mapbox-gl's MapLoadEvent (and MapSessionAPI), not TurnstileEvent — TurnstileEvent has no errorCb at all.
    • Bumping mapbox-gl will not fix this. remove() { this.errorCb = null; } is byte-identical in our pinned 3.24.0, in the latest published v3.30.0, and on main today. 3.30.0 is slightly worse — it changed pendingRequest from a cancelable to a plain boolean, so upstream removed even the ability to cancel the in-flight request on teardown.

    What is the root cause of that problem?

    A use-after-teardown race in mapbox-gl's telemetry, triggered by our map unmounting while its map.load telemetry POST is still in flight.

    MapLoadEvent.remove() nulls this.errorCb but does not cancel the pending request. When that request later fails, the completion handler calls this.errorCb(err) on null → TypeError. The throw happens inside a fetch().catch() with nothing downstream, so it surfaces as an unhandled rejection.

    The failure half is not a slow connection — events.mapbox.com is on common ad/privacy blocklists, so the POST reliably fails for a subset of users (upstream issue mapbox/mapbox-gl-js#13226, open since 2024). Blocked user + any map unmount = guaranteed throw. That explains the steady ~1.4 events per user rather than a rare race.

    Most important detail for prioritising: mapbox-gl calls postMapLoadEvent(..., () => {}) — the errorCb that fails to fire is an empty no-op. Nothing functional is lost. This is pure third-party noise with zero user-visible impact.

    Evidence and full data flow

    App side — we never touch mapbox-gl at runtime. Only MapViewImpl.web.tsx:3 imports its CSS. react-map-gl's <Map> at MapViewImpl.web.tsx:282 owns the instance, and @vis.gl/react-mapbox calls map.remove() in its unmount cleanup.

    Three distinct unmount triggers on this screen:

    1. Navigating away / completing the step (Navigation.goBack) — the Sentry route.
    2. A network blip. Both MapView.web.tsx:51 and MapViewImpl.web.tsx:277 gate on !isOffline, so going offline unmounts the map — and the same blip fails the in-flight POST. A correlated double-trigger.
    3. Mapbox token rotation clearing ONYXKEYS.MAPBOX_ACCESS_TOKEN (25-min refresh) empties accessToken → unmount.

    Upstream source (v3.30.0 src/util/mapbox.ts):

    this.postEvent(timestamp, additionalPayload, (err) => {
        if (err) { this.errorCb(err); }   // <-- errorCb is null here
        ...
    });
    remove() { this.errorCb = null; }     // <-- never cancels pendingRequest

    Why it's an unhandled rejection: in 3.24.0's ajax layer the TypeError thrown in .then() is caught by the sibling .catch(), which invokes the same broken callback a second time — and that throw has no handler left.

    Amplifier: mapLoadEvent and mapSessionAPI are module-level singletons shared by every Map. Unmounting any one map nulls errorCb globally, so one map's teardown can break another live map's in-flight request.

    Not reported upstream. Zero PRs and zero issues on mapbox/mapbox-gl-js mention errorCb as a defect (the three search hits are all about missing access tokens). No CHANGELOG entry from 3.25.0 through 3.31.0-rc.1 mentions telemetry, errorCb, or teardown.

    react-error-boundary cannot catch this — an unhandled promise rejection is not a React render error, so the boundary at MapView.web.tsx:33 is irrelevant here.

    What changes do you think we should make in order to solve the problem?

    1. Silence it in Sentry. Add a pattern for this.errorCb is not a function to ignoreErrors in src/setup/telemetry/setupSentry.ts:60-67. The array already carries exactly this kind of entry. Since the callback it fails to invoke is an empty no-op, suppression loses no signal.
    2. Add a patch-package patch guarding the two call sites — if (this.errorCb) this.errorCb(err) in MapLoadEvent.processRequests and MapSessionAPI.processRequests. Our patch infra is already in place (patches/, postinstall); there is no patches/mapbox-gl/ today. This keeps telemetry intact, so it does not touch the ToS-fenced code.
    3. File it upstream with the same one-line guard. Nobody has reported it, and the fix does not remove telemetry.

    Step 1 alone closes the Sentry issue. Steps 2–3 fix the actual throw.

    What alternative solutions did you explore? (Optional)

    Three rejected options, with why
    • Bump mapbox-gl past 3.24.0 — does not work. Unfixed in every release through 3.30.0 and on main; 3.30.0 makes cancellation impossible.
    • Disable telemetry via mapboxgl.config.EVENTS_URL = null — does not work. In 3.24.0 EVENTS_URL is a getter-only accessor derived from API_URL: the assignment is a silent no-op in sloppy mode and throws under ESM strict mode. There is no setTelemetryEnabled, no telemetry option on <Map>, and no env flag anywhere in the bundle. The only lever, API_URL, would break all tile and style requests. Object.defineProperty over the getter would technically work, but the telemetry call site is explicitly fenced with "REMOVAL OR MODIFICATION OF THE PRECEDING CODE VIOLATES THE MAPBOX TERMS OF SERVICE" — a contract question, not a code one.
    • reuseMaps prop on <Map> — technically effective (unmount takes recycle() instead of destroy(), so map.remove() never runs and errorCb is never nulled), but it changes map-instance lifetime semantics across mounts. I did not verify that waypoint markers and direction layers re-attach cleanly or that zoom/bounds reset correctly. Too much behavioural risk for a no-op-callback noise bug.
    • Delaying map.remove() until telemetry settles (option 2 in the issue body) — not reachable from App code; the teardown lives inside @vis.gl/react-mapbox's unmount effect, and blocking unmount on a third-party POST that ad blockers hang is worse than the bug.

    Related issues: I scanned open Expensify/App issues for errorCb / mapbox-gl distance-map crashes and found no duplicates or related reports.

    Confidence: high — every claim above is read from mapbox-gl's own source (installed 3.24.0, published v3.30.0, and main) plus the App call chain. Not reproduced live: triggering it needs events.mapbox.com blocked or failing at the moment of unmount, which is not reliably stageable in a test harness.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/100845#issuecomment-5619616094) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal. · view recording

  6. mountiny commented on Sep 11, 2026

    @mountiny
    ContributorAuthor

    @Pujan92 can you please review the proposal from Melvin and open it to the community if not good enough? Thanks

  7. Pujan92 commented on Sep 15, 2026

    @Pujan92
    Contributor

    I think better to fix this upstream to check the truthiness of this.errorCb here.

    I will look into it and open the issue in Mapbox. If they don't consider fixing it, then we can consider using patch-package.

  8. mountiny commented on Sep 17, 2026

    @mountiny
    ContributorAuthor

    Thanks, that would be great @Pujan92

  9. melvin-bot commented on Sep 18, 2026

    @melvin-bot

    @Pujan92 Whoops! This issue is 2 days overdue. Let's get this updated quick!

  10. 35 remaining items

  11. melvin-bot commented on Nov 11, 2026

    @melvin-bot

    @Pujan92

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.5.35-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2026-11-18. 🎊

    The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]

  12. expensify-chore-bot commented on Nov 17, 2026

    @expensify-chore-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  13. expensify-chore-bot commented on Nov 17, 2026

    @expensify-chore-bot

    Payment Summary

    Resolving PRs:

    BugZero Checklist (@mallenexpensify)

    • I have confirmed assignees, roles, and Upwork contracts look correct
    • I have paid out Upwork contracts / manual NewDot requests
    • [BugZero Assignee] I have created a GH issue for creating/updating the regression test once above steps have been agreed upon
  14. Pujan92 commented on Nov 19, 2026

    @Pujan92
    Contributor

    No Checklist Needed

    This was an upstream fix in the mapbox lib.

  15. mallenexpensify commented on Nov 19, 2026

    @mallenexpensify
    Contributor

    Claude posting on behalf of Matt:

    Ready. Job price: $250 (Pujan92 assigned 2026-09-10).

    • Pujan92 (Contributor): 100%, via NewDot

    Pujan92 wrote the PR. Melvin's summary lists Pujan92 as Reviewer, which is wrong.

    Pujan92 posted No Checklist Needed: comment. No deploy blockers.

    Next: pay. No Caps+Y.

    Evidence
    • Resolving PR 106319: upstream mapbox fix by Pujan92, merged 2026-11-09, production 2026-11-11, reviewed by mountiny. No revert.
    • Test videos: author 1/5.

    PAYPREP v1

  16. mallenexpensify commented on Nov 20, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @Pujan92 due $250 via NewDot

  17. twisterdotcom commented on Nov 20, 2026

    @twisterdotcom
    Contributor

    $250 approved for @Pujan92 in Report ID: R005IRJ2va14.

    Zapier Logs Run ID: 00040eee-f94e-aab2-ee81-8cc46d658d34

    SO: https://stackoverflowteams.com/c/expensify/questions/7582

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions