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

オープン
#26,317 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
swift
領域
mobile-dev

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

[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

主要言語
Swift
スター
3.9k
フォーク
1.2k
平均マージ
1日 23時間
マージ済み PR(30日)
136

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

wordpress-mobile/WordPress-iOS のほかの issue

wordpress-mobile/WordPress-iOS の issue をすべて見る

似ている issue

Swift の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。