Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXC_BAD_ACCESS with concurrent access to inner's HTTPDataLoader running tasks #44

Closed
malcommac opened this issue May 17, 2022 · 0 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@malcommac
Copy link
Collaborator

Bug Report

The issue is triggered when multiple concurrent tasks try to access the dataLoaders's dictionary inside the HTTPDataLoader class. This dictionary stored in-progress tasks by using as a key the URLSessionTask instance created by the underlying URLSession and as a value the HTTPDataLoaderResponse object.

This error can trigger an EXC_BAD_ACCESS crash both on-device and on simulator.

You can reproduce this issue easily by executing a great amount of concurrent tasks:

func test_concurrentNetworkCallsCrash() async throws {
        var requests = [HTTPRequest]()
        let newClient = HTTPClient(baseURL: nil)

        for _ in 0..<100 {
            let req = try! HTTPRequest(method: .get, "https://www.apple.com")
            requests.append(req)
        }
        
        await withThrowingTaskGroup(of: HTTPResponse.self, body: { group in
            for req in requests {
                group.addTask(priority: .high) {
                    let result = try await req.fetch(newClient)
                    print(result.data?.count ?? 0)
                    return result
                }
            }
            
        })
    }

We could fix it by using a lock on write.

@malcommac malcommac added the bug Something isn't working label May 17, 2022
@malcommac malcommac added this to the 1.5.0 milestone May 17, 2022
@malcommac malcommac self-assigned this May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant