aws / aws-lambda-runtime-interface-emulator

Apache License 2.0
915 stars 95 forks source link

Runtime error: invalid memory address or nil pointer dereference #97

Open tcmbilozub opened 1 year ago

tcmbilozub commented 1 year ago

The following error occurs when executing several simultaneous requests:


19 Jun 2023 22:05:39,909 [INFO] (rapid) ReserveFailed: AlreadyReserved panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x68c30f]

goroutine 131 [running]: go.amzn.com/lambda/rapidcore.(Server).Invoke.func2() /LambdaRuntimeLocal/lambda/rapidcore/server.go:653 +0xef created by go.amzn.com/lambda/rapidcore.(Server).Invoke /LambdaRuntimeLocal/lambda/rapidcore/server.go:636 +0x23d


Docker image: public.ecr.aws/lambda/python:3.8

nparker2020 commented 1 year ago

Hey @tcmbilozub I ran into this same error message, but it appears to be a different issue. For me, it turned out to be an incorrect path to the python executable that was passed to the runtime interface emulator. Posting here to hopefully help others.


Starting mock Lambda runtime:
16 Aug 2023 16:42:49,811 [INFO] (rapid) exec '/usr/bin/python' (cwd=/, handler=awslambdaric)
16 Aug 2023 16:42:51,574 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
16 Aug 2023 16:42:51,574 [INFO] (rapid) Configuring and starting Operator Domain
16 Aug 2023 16:42:51,574 [INFO] (rapid) Starting runtime domain
16 Aug 2023 16:42:51,574 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
16 Aug 2023 16:42:51,574 [INFO] (rapid) Starting runtime without AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN , Expected?: false
START RequestId: e4769e06-19d6-45c7-969f-a310d8769df9 Version: $LATEST
16 Aug 2023 16:42:51,574 [WARNING] (rapid) First fatal error stored in appctx: Runtime.InvalidEntrypoint
******************************************************************************************************************************************
16 Aug 2023 16:42:51,574 [ERROR] (rapid) Init failed InvokeID= error=fork/exec /usr/bin/python: no such file or directory
******************************************************************************************************************************************

16 Aug 2023 16:42:51,574 [INFO] (rapid) Starting runtime domain
16 Aug 2023 16:42:51,574 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
16 Aug 2023 16:42:51,575 [INFO] (rapid) Starting runtime without AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN , Expected?: false
16 Aug 2023 16:42:51,575 [WARNING] (rapid) Omitting fatal error Runtime.InvalidEntrypoint: Runtime.InvalidEntrypoint already stored
START RequestId: 9098b9f6-2ec1-4574-976c-c1f708284870 Version: $LATEST
16 Aug 2023 16:42:55,910 [INFO] (rapid) ReserveFailed: AlreadyReserved
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x699b8f]

goroutine 51 [running]:
go.amzn.com/lambda/rapidcore.(*Server).Invoke.func2()
        /LambdaRuntimeLocal/lambda/rapidcore/server.go:653 +0xef
created by go.amzn.com/lambda/rapidcore.(*Server).Invoke
        /LambdaRuntimeLocal/lambda/rapidcore/server.go:636 +0x23d
tcmbilozub commented 11 months ago

Temporarily solved this problem by downgrading to a lower version.

RUN curl -Lo /usr/local/bin/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/v1.10/aws-lambda-rie \ && chmod +x /usr/local/bin/aws-lambda-rie

benoit-laplante commented 11 months ago

Having same issue with simultaneous requests under python 3.8

(rapid) ReserveFailed: AlreadyReserved
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x699b8f]
goroutine 45 [running]:
go.amzn.com/lambda/rapidcore.(*Server).Invoke.func2()
     /LambdaRuntimeLocal/lambda/rapidcore/server.go:653 +0xef
 created by go.amzn.com/lambda/rapidcore.(*Server).Invoke
     /LambdaRuntimeLocal/lambda/rapidcore/server.go:636 +0x23d
achernyakov-rvbd commented 8 months ago

I too am hitting this when making simultaneous requests. Is there any workaround other than downgrading to an old version?

fs-aikito commented 5 months ago

The offending code is here

https://github.com/aws/aws-lambda-runtime-interface-emulator/blob/develop/lambda/rapidcore/server.go#L661-L666

It checks if Reserve() fails and logs message but then continues on as if nothing was wrong while reserveResp is nil causing this segfault immediatly when trying to access reserveResp.Token

jmehnle commented 3 months ago

The permanent link for this code section is: https://github.com/aws/aws-lambda-runtime-interface-emulator/blob/d37e08c13600eae4deb1329603f01a78363f360e/lambda/rapidcore/server.go#L661-L666

I looked at this code, and I'm not sure as to what a good fix might be. One possibility would be to pull the s.Reserve() call out of the go func into the main Invoke() body, which would make the s.Reserve() call synchronous, allowing us to return from Invoke() with an error. This appears to be roughly what the previous version of Invoke() did: https://github.com/aws/aws-lambda-runtime-interface-emulator/blob/a08886c27be3214fe7a1b72bd419e51eca01afa2/lambda/rapidcore/server.go#L577-L594

… but it seems undoing that would contravene the intent behind moving the s.Reserve() call into an asynchronous goroutine.

AWS, can someone please comment on what your plans are for addressing this regression?

jperezr21 commented 1 week ago

Any updates on this? Makes testing locally impossible for some use cases.

myedibleenso commented 1 week ago

Temporarily solved this problem by downgrading to a lower version.

RUN curl -Lo /usr/local/bin/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/v1.10/aws-lambda-rie \ && chmod +x /usr/local/bin/aws-lambda-rie

Thank you, @tcmbilozub , for this workaround. With the earlier version you identified at least the first request made can complete (tested with python 3.11).

Given its effect on concurrency and the popularity of lambda, I'm surprised this regression hasn't garnered more attention by now. Someone once said "speed matters in business." AWS lambda team, please consider prioritizing this for your customers.