Posts deleted locally by a list sync while still in use (umbrella for several crashes)

Aperta
#26,323 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
swift
Ambito
mobile

Direzione di ricerca

Start in PostRepository.swift at paginate(...) and the purgeExisting logic; trace how first-page syncs interact with open editors, saves, and in-flight updates. Use the shared repro recipe with Network Link Conditioner, then check any proposed fix against all five linked crashes and the related stale-post bugs.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

[Status] Needs Plan [Type] Bug Core Data Posts + Pages

Several crashes, and a few long-standing bugs, look like the same problem: a Post is deleted from Core Data while some part of the app is still using it, and that code then crashes or writes to it.

Mechanism (hypothesis, from the individual write-ups)

  • PostRepository.paginate(...) passes deleteOtherLocalPosts: offset == 0 (PostRepository.swift ~L506), which becomes purgeExisting (~L667). Every first-page sync of a post list deletes local posts that aren't in that page.
  • These syncs run often. Breadcrumbs show the main list re-syncing page 1 every few seconds, possibly triggered by NWPathMonitor reachability updates.
  • Places that still hold the deleted post then crash:
    • an in-flight save or status change (PostRepository, PostHelper.update)
    • an editor that's open or being opened (AztecPostViewController.init, GutenbergSettings.mustUseGutenberg)
    • a Posts search result row
    • While an editor is open, the post list stops observing changes (its fetch delegate is nil), so on-screen rows can point at deleted objects.

Crashes (Jetpack, last 30 days)

Issue Sentry Users (27.3) Crashes in
#26316 JETPACK-IOS-1JSW 78 (7.8× vs 27.2: a real regression) PostCategory.lookup after a quick status change
#26317 JETPACK-IOS-1BN2, 1CA4 51 + 32 Media.makeMedia(blog:), force-unwrapping blog.managedObjectContext!
#26318 JETPACK-IOS-1KJC 41 Blog.xmlrpcApi with post.blog == nil (crashes since #25869, 27.2)
#26319 JETPACK-IOS-1GFE (was 1HPP/1HQY) 46 classic editor init precondition
#26320 JETPACK-IOS-1KP9 (was 1JXN) 13 GutenbergSettings.mustUseGutenberg

27.3 has about 4.2× as many users as 27.2 in Sentry, so only 1JSW stands out per user. The others are steady and long-running.

Possibly related bugs: #24138 and #24245 (dashboard cards keep showing stale posts), and #24190 (trashing a stale draft can trash the published post).

Fix directions to evaluate

  1. Don't purge posts that are in use. Skip posts that have an open editor, a local revision, or an in-flight sync or save when purgeExisting runs.
  2. Check before using a post held across an await or a callback. Re-fetch by objectID with existingObject(with:), and bail out if isDeleted or managedObjectContext == nil, instead of force-unwrapping. That alone would turn most of these crashes into handled errors.
  3. Narrow the purge, for example only for list filters that are actually being refreshed, not on reachability-driven syncs.

A fix for (1) or (3) should be checked against all five crashes at once.

Shared repro recipe

Jetpack app, a WordPress.com site with more than 20 posts, and Network Link Conditioner set to add 2–3 s of latency.

  1. Open Posts. From a row's menu, change the status of a post that's near the bottom of the first page.
  2. While that request is in flight, pull to refresh, or toggle the network, so page 1 re-syncs.
  3. Variations: open a post in the editor, close it, and reopen it immediately. Open a post from Posts search while the list re-syncs.

Each linked issue has its own Sentry snapshot, breadcrumbs and event IDs.


Generated by Claude Code

Lingua principale
Swift
Stelle
3.9k
Fork
1.2k
Merge medio
1g 23h
PR unite (30g)
136

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wordpress-mobile/WordPress-iOS

Tutte le issue di wordpress-mobile/WordPress-iOS

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.