Skip to content

Crash on iOS when re-using background URLSession identifier #229

@samsonjs

Description

@samsonjs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions