Requests on a signed-out account's WordPressComRestApi crash the app
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- swift
- Lĩnh vực
- api, networking
Hướng nghiên cứu
Start with WordPressComRestApi.perform in WordPressComRestApi.swift and the task-creation path in HTTPClient.swift; trace how urlSession and uploadURLSession requests are created and invalidated. Then add the described sign-out/request unit test, taking care to prevent the account save from refaulting it. Done means a held API object returns an error rather than crashing after sign-out, and a slow-request sign-out does not crash or show an error.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Making a request on a signed-out account's WordPressComRestApi terminates the app. Each caller has to avoid this on its own, and new callers keep reintroducing it, so the fix belongs in WordPressComRestApi.
What happens
The app crashes with:
NSGenericException: Task created in a session that has been invalidated
Who is affected
Anyone who signs out while a feature still holds that account's API object and is about to make a request. The window is usually small, and a slow network makes it longer.
Root cause
Sign-out deletes the WPAccount, and WPAccount.prepareForDeletion calls invalidateAndCancelTasks() on the cached WordPressComRestApi. That invalidates its URLSessions for good, but the API object still accepts requests. The next request calls dataTask(with:) on the invalidated session, which raises an Objective-C exception. Swift can't catch it.
Known paths
- #25793 (open): Reader mention lookups. Confirmed in the Jetpack app on an iOS 27.0 simulator: signing out during the lookups crashed with the stack below, in 1 of 1 valid runs, with lookups delayed 6 s each by a local proxy. That PR needs its own fix regardless of this issue.
- #26136: the Notifications bell activity service. A guard is proposed there for the same reason.
NotificationSyncMediator.sync: crashes if sign-out lands between the hashes response and theloadNotescall. Reproduced in the unit-test host, not in the app.
The crash doesn't always happen. Refaulting the main-context WPAccount drops its cached API, so an object handed out earlier is never invalidated. Its requests then succeed with the removed account's token. That is a separate problem, and this issue doesn't fix it.
Suggested fix
Have WordPressComRestApi remember that it was invalidated, and return an error instead of creating a task:
private let isInvalidated = OSAllocatedUnfairLock(initialState: false)
@objc open func invalidateAndCancelTasks() {
isInvalidated.withLock { $0 = true }
for session in [urlSession, uploadURLSession] {
session.invalidateAndCancel()
}
}
The internal perform that both urlSession and uploadURLSession go through would then check first:
guard !isInvalidated.withLock({ $0 }) else {
return .failure(.connection(URLError(.cancelled)))
}
This sketch has not been compiled or run.
Open questions
- Remaining gap: sign-out can still land between that check and task creation. Closing it fully means holding the lock around task creation in
HTTPClient. - Other request paths: any code that uses these sessions without going through
performneeds the same check. - Error handling: check that callers treat
.cancelledas a quiet failure, with no error shown to someone who has just signed out.
Test plan
- Add a unit test that signs out, then makes a request on the held API object, and expects an error rather than a crash. Spin the run loop after creating the account, or its save refaults the account and the test passes without exercising the crash.
- Sign out during a slow request in the app and confirm there is no crash.
Stack from #25793 (Jetpack Debug build, head f6d731aff9)
CFNetwork
NSURLSession.task(for:completion:) (HTTPClient.swift:195)
closure #1 in closure #1 in NSURLSession.perform<A>(request:acceptableStatusCodes:taskCreated:fulfilling:errorType:)
NSURLSession.perform<A>(request:acceptableStatusCodes:taskCreated:fulfilling:errorType:)
WordPressComRestApi.perform<A>(request:fulfilling:decoder:taskCreated:session:)
WordPressComRestApi.perform<A>(_:URLString:parameters:fulfilling:decoder:) (WordPressComRestApi.swift:425)
WordPressComRestApi.perform(_:URLString:parameters:fulfilling:) (WordPressComRestApi.swift:383)
WordPressComReaderUserProfileService.fetchProfile(handle:) (ReaderUserProfileService.swift:39)
ReaderDetailCoordinator.resolveMentionProfiles(for:) (ReaderDetailCoordinator.swift:235)
closure #1 in ReaderDetailViewController.render(_:) (ReaderDetailViewController.swift:272)
Line numbers in the Reader files are from a build with temporary logging added.
- Ngôn ngữ chính
- Swift
- Star
- 3.9k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 136
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của wordpress-mobile/WordPress-iOS
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
wordpress-mobile/WordPress-iOS#26423 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Pri] Low [Status] Ready for Dev [Type] Bug /Me
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
wordpress-mobile/WordPress-iOS#26279 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Pri] Low [Status] Ready for Dev [Type] Bug Share Extension
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
wordpress-mobile/WordPress-iOS#26276 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Pri] Low [Status] Ready for Dev [Type] Bug Blogging Prompts Notifications
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
wordpress-mobile/WordPress-iOS#26256 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Status] Ready for Dev [Type] Bug Reader
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
wordpress-mobile/WordPress-iOS#26254 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của wordpress-mobile/WordPress-iOS
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Optional callbacks log "Unable to create JSCallback" when passed nullCó thể đã có người làm @cmsj đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
cmsj/Hammerspoon2#464 ·
-
android bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
VocaHQ/vocaphone#470 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
new-compilers request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
compiler-explorer/compiler-explorer#9640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
RevenueCat/purchases-ios#8312 ·
Maintainer thường phản hồi trong vòng 1 ngày