Skip to content

Shutdown must ALWAYS be called for shutdownIfNotStarted=true #106

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

Closed
fabianfett opened this issue Aug 24, 2021 · 0 comments · Fixed by #109
Closed

Shutdown must ALWAYS be called for shutdownIfNotStarted=true #106

fabianfett opened this issue Aug 24, 2021 · 0 comments · Fixed by #109

Comments

@fabianfett
Copy link
Member

fabianfett commented Aug 24, 2021

To use Lifecycle in lambda runtime, we need to find a way that it can shutdown instances that don't need a startup. Example handler:

import AWSLambdaRuntime
import AsyncHTTPClient

// introductory example, the obligatory "hello, world!"
@main
struct HelloWorldHandler: AsyncLambdaHandler {
    typealias In = String
    typealias Out = String

    let httpClient: HTTPClient

    init(context: Lambda.InitializationContext) async throws {
        self.httpClient = HTTPClient(eventLoopGroupProvider: .shared(context.eventLoop))
        context.lifecycle.register(label: "shutdown", start: .none, shutdown: .async {
            self.httpClient.shutdown($0)
        }, shutdownIfNotStarted: true)

        throw MyError()
    }

    func handle(event: String, context: Lambda.Context) async throws -> String {
        "hello, world"
    }
}

In this case the httpClient still needs a call to shutdown. This is currently not happening. The use case that we should enable is abstracted below:

Failing test case

func testShutdownIfNotStarted() {
    var shutdownCalled = false
    
    let lifecycle = ComponentLifecycle(label: "test")
    lifecycle.register(label: "shutdown", start: .none, shutdown: .sync {
        shutdownCalled = true
    }, shutdownIfNotStarted: true)
    
    lifecycle.shutdown()
    XCTAssertTrue(shutdownCalled)
}
@fabianfett fabianfett changed the title Shutdown must ALWAYS be called for shutdownIfNotStarted Shutdown must ALWAYS be called for shutdownIfNotStarted=true Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant