Skip to content
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

Fiber proxy sets context to cancelled #206

Open
0ndermijner opened this issue Oct 1, 2024 · 0 comments
Open

Fiber proxy sets context to cancelled #206

0ndermijner opened this issue Oct 1, 2024 · 0 comments

Comments

@0ndermijner
Copy link

0ndermijner commented Oct 1, 2024

When using the ProxyWithContext function from the Fiber proxy, the context is immediately set to cancelled once it transitions from the Lambda context in the handler function to the Fiber fiber.Ctx struct. This results in subsequent API calls to AWS services that rely on the context to fail, as the context is already cancelled.

Runtime and configuration

  • API Gateway: Regional rest API
  • Lambda runtime: Amazon Linux 2023; arn:aws:lambda:eu-west-1::runtime:394919924951bb234aa650732bf2a1cc74b5e6aa1d263b5f333fbd029cc8e978
  • Go version: 1.23.1
  • Fiber version: github.com/gofiber/fiber/v2 v2.52.5
  • Lambda proxy version: github.com/awslabs/aws-lambda-go-api-proxy v0.16.2
  • Lambda go version: github.com/aws/aws-lambda-go v1.47.0

Reproducing the issue

Below a very simple fiber app that will fatal out with a error state.

Go code

package main

import (
	"context"
	"log"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	fiberAdapter "github.com/awslabs/aws-lambda-go-api-proxy/fiber"
	"github.com/gofiber/fiber/v2"
)

var fiberLambda *fiberAdapter.FiberLambda

func init() {
	app := fiber.New()

	app.Use(func(c *fiber.Ctx) error {
		if c.Context().Err() != nil {
			log.Fatalf("Fiber context is in error state: %v", c.Context().Err())
		}
		return c.SendString("Hello")
	})

	fiberLambda = fiberAdapter.New(app)
}

func handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
	if ctx.Err() != nil {
		log.Fatalf("Lambda context is in error state: %v", ctx.Err())
	}
	return fiberLambda.ProxyWithContext(ctx, req)
}

func main() {
	lambda.Start(handler)
}

Go mod file

module reproduce-fiber-erorr

go 1.23.1

require (
	github.com/aws/aws-lambda-go v1.47.0
	github.com/awslabs/aws-lambda-go-api-proxy v0.16.2
	github.com/gofiber/fiber/v2 v2.52.5
)

require (
	github.com/andybalholm/brotli v1.1.0 // indirect
	github.com/google/uuid v1.6.0 // indirect
	github.com/klauspost/compress v1.17.10 // indirect
	github.com/mattn/go-colorable v0.1.13 // indirect
	github.com/mattn/go-isatty v0.0.20 // indirect
	github.com/mattn/go-runewidth v0.0.16 // indirect
	github.com/rivo/uniseg v0.4.7 // indirect
	github.com/valyala/bytebufferpool v1.0.0 // indirect
	github.com/valyala/fasthttp v1.56.0 // indirect
	github.com/valyala/tcplisten v1.0.0 // indirect
	golang.org/x/sys v0.25.0 // indirect
)

Logging output:

START RequestId: 5abeae99-e0c9-4edd-acde-d6773e636304 Version: $LATEST
2024/10/01 09:21:49 Fiber context is in error state: context canceled
RequestId: 5abeae99-e0c9-4edd-acde-d6773e636304 Error: Runtime exited with error: exit status 1 Runtime.ExitError
END RequestId: 5abeae99-e0c9-4edd-acde-d6773e636304
REPORT RequestId: 5abeae99-e0c9-4edd-acde-d6773e636304 Duration: 31.88 ms Billed Duration: 109 ms Memory Size: 128 MB Max Memory Used: 20 MB Init Duration: 76.84 ms 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant