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

Multiple AF.upload cannot be concurrent #3810

Open
1 task done
baiyidjp opened this issue Jan 6, 2024 · 1 comment
Open
1 task done

Multiple AF.upload cannot be concurrent #3810

baiyidjp opened this issue Jan 6, 2024 · 1 comment
Assignees

Comments

@baiyidjp
Copy link

baiyidjp commented Jan 6, 2024

ℹ Please fill out this template when filing an issue.
All lines beginning with an ℹ symbol instruct you with what info we expect. You can delete those lines once you've filled in the info.

Per our *CONTRIBUTING guidelines, we use GitHub for
bugs and feature requests, not general support. Other issues should be opened on Stack Overflow with the tag alamofire.

Please remove this line and everything above it before submitting.

What did you do?

When I use AF.upload to initiate multiple upload tasks, the multiple upload tasks are always executed serially. As a result, other requests I want to execute after the upload is successful must also be executed after all uploads are completed. In other words, upload seems to be blocking other requests. But this is not the case when I use AFNetwork

What did you expect to happen?

When I use AF.upload to initiate multiple upload tasks, they can be executed concurrently without blocking other requests.

What happened instead?

Blocking other requests

Alamofire Environment

**Alamofire Version: 5.8.1
**Dependency Manager: cocoapods
**Xcode Version: 15.1
**Swift Version: Swift 5
**Platform(s) Running Alamofire: 17.1
**macOS Version Running Xcode: 14.2.1

Demo Project

        DispatchQueue.global().async {
            AF.upload(
                    multipartFormData: {
                        $0.append(fileData, withName: name, fileName: fileName, mimeType: mimeType)
                    },
                    to: uploadURL,
                    headers: headers)
                .responseDecodable(of: APIResponse<APIResult>.self) { response in
                    DispatchQueue.main.async {
                        /// other request
                    }
                }
        }
@jshier
Copy link
Contributor

jshier commented Feb 6, 2024

There's nothing in Alamofire that triggers this behavior. If you're seeing this it's likely URLSession is attempting to optimize your connectivity or otherwise preventing the app from overloading the network connections. Or it may be that your server doesn't allow multiple uploads at the same time.

P.S. The DispatchQueue usage you have here is unnecessary. Neither the global() or the call back to main does anything. Alamofire completion handlers are on main by default.

@jshier jshier self-assigned this Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants