Crash on iOS when re-using background URLSession identifier
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- swift
- Domain
- mobile, networking
Research direction
The affected entry point is TUSClient.deinit; inspect how the URLSession configuration identifier distinguishes background from foreground sessions. Reproduce the reuse case with a background identifier and verify that deinitialization no longer invalidates that session while foreground sessions still finish and invalidate their tasks.
Written by the indexing model from the issue text.
Description
TUSClient.deinit finishes and invalidates the session even when it's a background session. In my app I was re-using the same session ID after changing service environments (prod/staging/dev) and that causes this crash:
BackgroundSession <5B232D47-B8F1-4848-9A69-8196786E5921> attempted to create a NSURLSessionDataTask in a session that has been invalidated
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Task created in a session that has been invalidated'
*** First throw call stack:
(0x18ce25044 0x18a2bdabc 0x18e51c780 0x18e31997c 0x18e31607c 0x103cb2064 0x103ca919c 0x18e3170c4 0x18e31932c 0x1106bd630 0x1106dd500 0x1106b4944 0x103c98584 0x103cb2064 0x103ca091c 0x103ca15a4 0x103cad894 0x103caceb0 0x21720ca0c 0x21720caac)
libc++abi: terminating due to uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Task created in a session that has been invalidated'
*** First throw call stack:
(0x18ce25044 0x18a2bdabc 0x18e51c780 0x18e31997c 0x18e31607c 0x103cb2064 0x103ca919c 0x18e3170c4 0x18e31932c 0x1106bd630 0x1106dd500 0x1106b4944 0x103c98584 0x103cb2064 0x103ca091c 0x103ca15a4 0x103cad894 0x103caceb0 0x21720ca0c 0x21720caac)
terminating due to uncaught exception of type NSException
Should TUSClient.deinit only finish and invalidate tasks when it's a foreground session and its configuration identifier is nil? That fixes the issue here and I think it's correct, but wanted to talk it over before opening up a PR.
- Dominant language
- Swift
- Stars
- 245
- Forks
- 129
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tus/TUSKit
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
visionOS support !Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
manaflow-ai/cmux#59692 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
modelcontextprotocol/swift-sdk#381 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days
-
App 仍在下载和解析用不上的会话列表Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
vibe-cafe/vibe-usage-app#125 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
touyou/CheckItOut#39 ·
Maintainers usually reply within 1 day