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

Serverless generator incorrectly handles exceptions #306

Open
p0wx opened this issue Mar 28, 2024 · 0 comments
Open

Serverless generator incorrectly handles exceptions #306

p0wx opened this issue Mar 28, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@p0wx
Copy link

p0wx commented Mar 28, 2024

We run runpod serverless docker on our server for debugging.
We have a handler function that looks like this:

async def handler(job):
    assert False, "My assert"
    yield "Hello"

We make a request like this that will invoke assert False, "My assert".

$ curl --request POST   --url http://localhost:8000/runsync   --header "accept: application/json"   --header "content-type: application/json"   --data '{...}'
Internal Server Error

We expected instead to get something like:

{"id":...,"status":"FAILED","error":"My assert"}

In server logs:

ERROR  | test-e8a0ec12-fee5-48c9-85fd-b77d6ed3753b | My assert
ERROR:    Exception in ASGI application
Traceback (most recent call last):
...
  File "/usr/local/lib/python3.10/dist-packages/runpod/serverless/modules/rp_fastapi.py", line 305, in _sim_runsync
    job_output['output'].append(stream_output["output"])
KeyError: 'output'

In serverless/modules/rp_fastapi.py

    async def _sim_runsync(self, job_request: DefaultRequest) -> JobOutput:
        """ Development endpoint to simulate runsync behavior. """
        assigned_job_id = f"test-{uuid.uuid4()}"
        job = TestJob(id=assigned_job_id, input=job_request.input)
        if is_generator(self.config["handler"]):
            generator_output = run_job_generator(self.config["handler"], job.__dict__)
            job_output = {"output": []}
            async for stream_output in generator_output:
                job_output['output'].append(stream_output["output"])
        else:
            job_output = await run_job(self.config["handler"], job.__dict__)
        if job_output.get('error', None):
            return jsonable_encoder({
                "id": job.id,
                "status": "FAILED",
                "error": job_output

Here if is_generator and stream_output is like {"error": ...} then line stream_output["output"] raises an error. So instead of error response from the server we get 500 internal server error.

Versions

  • OS: Ubuntu 19.10
  • Python: 3.11.8
  • runpod (python): 1.6.2
@p0wx p0wx added the bug Something isn't working label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants