Skip to content

Shutdown procedure for local testing #121

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 Jun 11, 2020 · 4 comments · Fixed by #122
Closed

Shutdown procedure for local testing #121

fabianfett opened this issue Jun 11, 2020 · 4 comments · Fixed by #122
Assignees
Milestone

Comments

@fabianfett
Copy link
Member

fabianfett commented Jun 11, 2020

In a non-trivial Lambda we might use an AHC, which we initialize with a factory method like this:

class MyLambdaHandler: EventLoopLambdaHandler {
    typealias In = SQS.Event
    typealias Out = Void

    let httpClient: HTTPClient

    static func create(_ eventLoop: EventLoop) -> EventLoopFuture<ByteBufferLambdaHandler> {
        let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoop))
        return eventLoop.makeSucceededFuture(MyLambdaHandler(httpClient: httpClient))
    }

    private init(httpClient: HTTPClient) {
        self.httpClient = httpClient
    }

    func handle(context: Lambda.Context, payload: SQS.Event) -> EventLoopFuture<Void> {
        // not interesting
    }
}

Lambda.run(MyLambdaHandler.create)

We currently don't have any chance to stop the httpClient in a coordinated way, if we stop the LocalTestServer, which closes the Lambda.

This is why I propose the following:

We expand the ByteBufferLambdaHandler protocol with a function syncShutdown() throws which will be invoked, if the Lambda is stopped. We supply a default empty implementation so that developers only need to deal with it if they run into a problem.

@tomerd @weissi @ktoso @adam-fowler wdyt?

@adam-fowler
Copy link
Member

In the SNS to Slack example I posted I had to make the Lambda a class and shutdown the HTTPClient in the deinit. It would be cleaner if we could do it inside a syncShutdown.

@weissi
Copy link
Contributor

weissi commented Jun 11, 2020

That sounds like a great and necessary addition. Forcing people to do lifecycle management in deinit will lead to really bad problems further down the line.

@tomerd
Copy link
Contributor

tomerd commented Jun 11, 2020

+1 good catch

@ktoso
Copy link
Contributor

ktoso commented Jun 12, 2020

Approach sounds good @fabianfett 👍

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