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

Python lambda times out when an unhandled error occurs, instead of terminating and forwarding the error to FunctionError. #1823

Open
ynaydenov-qb opened this issue Sep 13, 2024 · 0 comments

Comments

@ynaydenov-qb
Copy link

Bug Report

The python lambda times out if an unhandled error occurs (for example a runtime exception), the expected behaviour is to terminate the funtion and when the lambda is invoked to populate the FunctionError of the response with the error. However no information about the unhandled error is shown and the lambda continues to execute until a timeout. After some digging the problems seems to come from the invoke.py file in src/lambda/handler-runner/python-runner. Another thing to consider is that if an error occur during the imports (before the handler lambda is invoked) this also results in a time out, but should yield an error send again to the FunctionError.

Current Behavior

The python lambda times out if an unhandled error occurs instead of terminating.

Sample Code

from aws_lambda_typing import context, events

raise Exception("Random exception occurs")

def handler(event: events.EventBridgeEvent, _ctx: context.Context):
...
  • file: serverless.yml
service: my-service

plugins:
  - serverless-python-requirements
  - serverless-plugin-ifelse
  - serverless-prune-plugin
  - serverless-offline

provider:
  runtime: python3.11
  stage: dev

functions:
  factors:
    handler: src.handlers.factors.handler
    timeout: 29

Expected behavior/code

After encountering unhandled exception the lambda should be terminated and immediate response should be returned with the error encountered.

Environment

  • serverless version: v3.39.0
  • serverless-offline version: v14.0.0
  • python version: v3.11
  • OS: macOS 14.6.1

Possible Solution

Use a try-except block to handle the error that is thrown and return the information using the sys.stdout.write() with argument which contains __offline_payload__ with information about the error as JSON and status_code set to 500 for example.

Additional context/Screenshots

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