soto-project / soto

Swift SDK for AWS that works on Linux, macOS and iOS
https://soto.codes
Apache License 2.0
878 stars 83 forks source link

AWSClient still working on macOS after calling syncShutdown. #609

Closed marius-se closed 1 year ago

marius-se commented 2 years ago

Describe the bug On macOS the AWSClient is still working after I called the syncShutdown method. Compiling the exact same code on Ubuntu results in the "expected" behaviour: AWS requests not working anymore since the client shut down.

To Reproduce I noticed this behaviour while working with S3.

  1. Download the minimal, reproducible example project: sotobug.zip
  2. Create a regular S3 bucket on AWS.
  3. Open the attached project and fill in the blanks (region, bucket, access key, secret key)
  4. Run the executable on macOS
  5. Run the docker container (docker build . -t sotobug && docker run sotobug)

On macOS the request will still succeed, on ubuntu it will not return at all.

Expected behavior On both operating systems the request should not succeed and maybe even throw an error.

Setup (please complete the following information):

adam-fowler commented 2 years ago

Did you provide the AWSClient with a shared HTTPClient or EventLoopGroup. If not I imagine this is something to do with the default EventLoopGroup used by macOS.

marius-se commented 2 years ago

HTTPClientProvider.createNew HTTPClient will be created by AWSClient. When shutdown is called, created HTTPClient will be shut down as well.

adam-fowler commented 2 years ago

Ok this is probably an issue with the default EventLoopGroup on macOS which is NIOTSEventLoopGroup from swift-nio-transport-services. If you want to chase this then I would add a bug to AsyncHTTPClient.

This isn't really something that can be fixed in Soto.

marius-se commented 2 years ago

Okay I'll definitely try to investigate! However I have no clue about SwiftNIO/ AsyncHTTPClient so I'll probably forward this bug in a few days. Thanks anyways!

marius-se commented 2 years ago

Hmm I couldn't reproduce this behaviour with a plain async-http-client. Trying to fire a request after calling HTTPClient.shutdown() throws HTTPClientError.alreadyShutdown. Here is the (async-http-client) code:

import AsyncHTTPClient

@main
struct Main {
    static func main() async throws {
        let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)

        try await httpClient.shutdown()

        let request = HTTPClientRequest(url: "https://apple.com/")
        let response = try await httpClient.execute(request, timeout: .seconds(30)) // throws HTTPClientError.alreadyShutdown
    }
}
marius-se commented 2 years ago

In Soto however calling S3.signURL(url:httpMethod:expires:) after AWSClient.shutdown() does not throw an error. (where S3 uses an AWSClient created with HTTPClientProvider.createNew). See the sample project above.

adam-fowler commented 2 years ago

signURL doesn't use the HTTPClient. All it does is generate a URL so that isn't really a like for like test

marius-se commented 2 years ago

Ohhh that makes sense. But still, shouldn't AWSClient complain if we try to access it after calling shutdown, even if it's just signURL? What do you think?

adam-fowler commented 2 years ago

I guess I could add a check into the signURL and signHeaders calls. I'm not sure it really makes much difference though.

adam-fowler commented 1 year ago

I don't think this is an issue so am going to close it

marius-se commented 1 year ago

oh sorry, yep can be closed!