Crash in Media.makeMedia(blog:) when a post is deleted while it's being saved (EXC_BREAKPOINT makeMediaWithBlog:)

Abierto
#26,317 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
swift
Área
mobile-dev

Línea de trabajo

Start with PostRepository.swift at _sync and update, then trace the calls through PostHelper.m and Media+Blog.swift to Media.makeMedia(blog:). Build the Jetpack scheme and follow the repro steps, including syncing the Posts list while a save is in flight. Done looks like confirming the failure and ensuring that scenario no longer crashes; post the results here and update the issue status.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

[Status] Needs Plan [Status] Needs Repro [Type] Crash Core Data Posts + Pages

Likely shares a root cause with #26316, #26318, #26319, #26320. See #26323: posts are deleted locally by a first-page list sync while still in use.

Sentry: JETPACK-IOS-1BN2, JETPACK-IOS-1CA4

Sentry snapshot (as of Oct 30, 2026)

Fatal EXC_BREAKPOINT (a Swift force-unwrap trap) in Media.makeMedia(blog:). It has been ongoing since June 2024: 1BN2 has 509 events from 117 users, and 1CA4 has 250 events from 81 users.

Last 30 days 1BN2 users 1CA4 users
27.3 51 32
27.2 16 7

27.3 has about 4.2× as many error-reporting users as 27.2 (2,388 vs 573), so these numbers are flat per user, not a regression. Most events are on iPhone, with some on iPad (2 of the 8 sampled 1BN2 events), almost all on iOS 26.x and 27.x. Some users crash repeatedly.

Stack

Both groups have the same crash and differ only in the caller:

  • 1BN2: PostRepository._sync (PostRepository.swift:156) → PostHelper.update(post, with: remotePost, …)
  • 1CA4: PostRepository.update (PostRepository.swift:216), the quick-edit patch → PostHelper.update(...)

Both then go PostHelper.m:43 (post.featuredImage = [Media existingOrStubMediaWithMediaID:… inBlog:post.blog]) → Media.existingOrStubMediaWith (Media+Blog.swift:51) → Media.makeMedia(blog:) (Media+Blog.swift:19), which does makeMedia(in: blog.managedObjectContext!). The force-unwrap is the crash.

So it only happens when the server returns a featured image (postThumbnailID != nil) that isn't cached locally, and post.blog has no context.

Breadcrumbs (3 events sampled)
  • The trigger was a save, every time. The crash comes right after a POST …/posts/{id}?context=edit returns 200, from the editor (EditPostViewController → GutenbergViewController, closed with Close), from PublishPostViewController, or from a post-list context-menu action.
  • Usually after returning to the app (2 of 3). The app came back to the foreground minutes to hours later, and the Posts list re-synced (status=draft,pending or publish,private) while the request was in flight.
  • Images uploaded first (1 of 3). In one event, images were added through PHPickerViewController and uploaded just before the save.
Candidate code (hypothesis)
  • The post is deleted during the network await. _sync and update read post again on the main context after await _patch(...) or await _create(...). If a Posts list sync, a trash or a blog removal deletes the post during that await, post.blog returns nil for the deleted object, blog.managedObjectContext is nil, and the force-unwrap traps.
  • No guard. PostRepository never checks post.isDeleted or post.managedObjectContext after the await.
  • Same cause as #26318. That crash is in _create before the request is even sent: post.blog is nil there too.

Fix direction:

  • After each await in _sync and update, return early (or throw) if post.managedObjectContext == nil || post.isDeleted.
  • Make makeMedia(blog:) fail softly instead of force-unwrapping.
Repro to try
  1. Turn on Network Link Conditioner on the host (3G, or 2+ s latency) so save requests take a while.
  2. On a WordPress.com site, open a published post that has a featured image, then make sure that image isn't in the app's Media cache: sign in fresh or relaunch with -ui-test-reset-everything, and don't open Media.
  3. Edit the post and tap Update. While the request is in flight, delete the post locally:
    • pull to refresh the Posts list after trashing the post on the web, or
    • trash it from the list's context menu.
  4. Also try the quick-edit path (1CA4): change the post's status or visibility from the list's context menu, then trigger a list sync before it finishes.
  5. Pass: the crash in Media.makeMedia(blog:), or confirmation in the debugger that post.isDeleted is true after the await.
Events
  • 63ff7b65a49046b3b6e8a128bee10bd2 (1BN2)
  • b6ca8271b3b040ec8f1e65fb70d0ebef (1BN2, iPad)
  • 14391744a1f14fe79741894f60ab19a5 (1BN2)
  • 1fca673390b34f64bd0f7f7dd629c48c (1CA4)
  • bf5edd9208ae4c5cad1db96e29fead2b (1CA4)

Build the Jetpack scheme and sign in using docs/simulator-sign-in.md, with bundle ID com.automattic.jetpack.

When you're done: post the results here. If you now have reliable steps, remove [Status] Needs Repro. If you found the cause and a fix approach, remove [Status] Needs Plan and add [Status] Ready for Dev. Remove Simulator Testable when you're finished.


Generated by Claude Code

Lenguaje dominante
Swift
Estrellas
3.9k
Forks
1.2k
Merge medio
1 d 23 h
PR fusionados (30 d)
136

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de wordpress-mobile/WordPress-iOS

Todos los issues de wordpress-mobile/WordPress-iOS

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.