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

Precondition-fail in Swift-NIO #93

Closed
everlof opened this issue Dec 13, 2018 · 4 comments
Closed

Precondition-fail in Swift-NIO #93

everlof opened this issue Dec 13, 2018 · 4 comments

Comments

@everlof
Copy link

everlof commented Dec 13, 2018

I use version 2.0.2 of "aws-sdk-swift".

Using the code below, I get a precondition failure in Swift-NIO.

            let bucket = "xxx-storage"
            let s3 = S3(
                accessKeyId: "MY_ACCESS_KEY",
                secretAccessKey: "MY_SECRET_ACCESS_KEY)


            // Upload text file to the s3
            let bodyData = "hello world".data(using: .utf8)!
            let putObjectRequest =
                S3.PutObjectRequest(acl: .publicRead,
                                    bucket: bucket,
                                    contentLength: Int64(bodyData.count),
                                    key: "hello.txt",
                                    body: bodyData)
            let ret = try s3.putObject(putObjectRequest)

I looks like this:

screenshot 2018-12-13 at 11 35 47

I can't really solve it myself. I see there's some comments regarding the code:

//TODO(jmca) don't block

And:

//TODO(jmca) learn how to map response to validate and return
// a future of generic Output: AWSShape

Anyone know how this could be solved?

@jonnymacs
Copy link
Member

@everlof ok yes, I see this as well. Looks like this code was added since we integrated nio, but it is a good addition as indicated by the list of reasons that invoking wait on the main event loop is a bad idea.

https://github.com/apple/swift-nio/blame/master/Sources/NIO/EventLoopFuture.swift#L801

Until we have support for running nio requests w/o the invoking wait you need to wrap calls in a DispatchQueue.global().async {} block

try

DispatchQueue.global().async { 
 let ret = try s3.putObject(putObjectRequest)
}

@jonnymacs
Copy link
Member

@everlof any luck?

@everlof
Copy link
Author

everlof commented Jan 5, 2019

Thanks for the feedback! I Haven't had time to try it out yet, other things got in the way. Ill be sure to update here as soon as I've tried the workaround!

@jonnymacs
Copy link
Member

this is resolved in 3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants