Skip to content

Local Server Immediate Exit code: 0 (Xcode 12 b3) #148

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
IrvTheSwirv opened this issue Jul 29, 2020 · 7 comments · Fixed by #155
Closed

Local Server Immediate Exit code: 0 (Xcode 12 b3) #148

IrvTheSwirv opened this issue Jul 29, 2020 · 7 comments · Fixed by #155
Assignees
Labels
kind/bug Feature doesn't work as expected.

Comments

@IrvTheSwirv
Copy link

Wondering if this is an Xcode 12 beta 3 issue:

Having had this issue with my own first attempt at a simple swift lambda I tried building and running the MyLambda example project here and had the same result. If I run the project without the LOCAL_LAMBDA_SERVER_ENABLED flag I get the expected:

2020-07-29T12:22:40+0100 info Lambda : lambda lifecycle starting with Configuration General(logLevel: info)) Lifecycle(id: 148308112161193, maxTimes: 0, stopSignal: TERM) RuntimeEngine(ip: 127.0.0.1, port: 7000, keepAlive: true, requestTimeout: nil 2020-07-29T12:22:40+0100 error Lambda : lifecycleIteration=0 could not fetch work from lambda runtime engine: badStatusCode(NIOHTTP1.HTTPResponseStatus.unprocessableEntity) 2020-07-29T12:22:40+0100 error Lambda : lifecycleIteration=0 lambda invocation sequence completed with error: badStatusCode(NIOHTTP1.HTTPResponseStatus.unprocessableEntity) 2020-07-29T12:22:40+0100 info Lambda : shutdown completed Program ended with exit code: 0

However, if I add the LOCAL_LAMBDA_SERVER_ENABLED flag and run, the process starts and finishes immediately and the only output is the following:

Program ended with exit code: 0

Some pointers on where to look to resolve this would be great.

@IrvTheSwirv
Copy link
Author

IrvTheSwirv commented Jul 29, 2020

I've managed to step through the LocalServer code and found that the error is occurring in EvenLoopFuture in the wait() function (Line 928). The error is:

(Result<(),Error>?) $R0 = failure {
failure = {
failureDescription = "bind(descriptor:ptr:bytes:)"
error = errno (errno = 48)
}

@fabianfett
Copy link
Member

@IrvTheSwirv
Copy link
Author

@IrvTheSwirv I hope this helps: https://fabianfett.de/getting-started-with-swift-aws-lambda-runtime#step-4-test-your-lambda-locally

Hi. @fabianfett Thanks but the problem happens when I add that flag. I managed to trace it to an error occurring inside the code that sets up the local server (see above) but I'm a little stuck beyond that.

@fabianfett
Copy link
Member

fabianfett commented Jul 29, 2020

@IrvTheSwirv Interesting... IMHO the most interesting part so far is that you get an HTTPResponseStatus.unprocessableEntity status code from . I just had Xcode12b2 installed. Grabbing b3 right now to reproduce.

The error you're getting is originating here:

case (.GET, let url) where url.hasSuffix(Consts.getNextInvocationURLSuffix):
    // check if our server is in the correct state
    guard case .waitingForLambdaRequest = Self.invocationState else {
        self.logger.error("invalid invocation state \(Self.invocationState)")
        self.writeResponse(context: context, response: .init(status: .unprocessableEntity))
        return
    }

Do you have by accident two Lambda running in parallel?

@tomerd
Copy link
Contributor

tomerd commented Jul 30, 2020

Do you have by accident two Lambda running in parallel?

or maybe the default port (7000) is already taken by another program?

@IrvTheSwirv
Copy link
Author

@tomerd @fabianfett fresh eyes looking at it again this morning and you are correct Tomer, it was a process on another project I'm working on periodically listening on ports in a range around 7000 and happened to be on those ports (even after reboots) which now explains the

failureDescription = "bind(descriptor:ptr:bytes:)"

I was seeing when stepping through the code.

Would it be fair to say the fact that the library terminates with no message and exit code 0 if it can't bind to port 7000 should be considered a bug? That cost me a day and a half of time when a message would have helped me resolve the issue immediately.

@tomerd
Copy link
Contributor

tomerd commented Jul 30, 2020

thanks @IrvTheSwirv yes lets track this is a bug to handle this kind of error better

@tomerd tomerd added the kind/bug Feature doesn't work as expected. label Jul 30, 2020
@tomerd tomerd linked a pull request Aug 5, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Feature doesn't work as expected.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants