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

Handling 500 Errors #71

Open
pattisdr opened this issue Jun 30, 2022 · 2 comments
Open

Handling 500 Errors #71

pattisdr opened this issue Jun 30, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@pattisdr
Copy link

Bug Description

500 Errors in Fidesops are hard to debug without turning off fideslog logging, because we get a RuntimeError: asyncio.run() cannot be called from a running event loop error from fideslog.

/usr/local/lib/python3.9/site-packages/requests/sessions.py:659: in patch
    return self.request("PATCH", url, data=data, **kwargs)
/usr/local/lib/python3.9/site-packages/starlette/testclient.py:476: in request
    return super().request(
/usr/local/lib/python3.9/site-packages/requests/sessions.py:587: in request
    resp = self.send(prep, **send_kwargs)
/usr/local/lib/python3.9/site-packages/requests/sessions.py:701: in send
    r = adapter.send(request, **kwargs)
/usr/local/lib/python3.9/site-packages/starlette/testclient.py:270: in send
    raise exc
/usr/local/lib/python3.9/site-packages/starlette/testclient.py:267: in send
    portal.call(self.app, scope, receive, send)
/usr/local/lib/python3.9/site-packages/anyio/from_thread.py:283: in call
    return cast(T_Retval, self.start_task_soon(func, *args).result())
/usr/local/lib/python3.9/concurrent/futures/_base.py:446: in result
    return self.__get_result()
/usr/local/lib/python3.9/concurrent/futures/_base.py:391: in __get_result
    raise self._exception
/usr/local/lib/python3.9/site-packages/anyio/from_thread.py:219: in _call_func
    retval = await retval
/usr/local/lib/python3.9/site-packages/fastapi/applications.py:269: in __call__
    await super().__call__(scope, receive, send)
/usr/local/lib/python3.9/site-packages/starlette/applications.py:124: in __call__
    await self.middleware_stack(scope, receive, send)
/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py:184: in __call__
    raise exc
/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py:162: in __call__
    await self.app(scope, receive, _send)
/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py:68: in __call__
    response = await self.dispatch_func(request, call_next)
src/fidesops/main.py:77: in dispatch_log_request
    prepare_and_log_request(
src/fidesops/main.py:100: in prepare_and_log_request
    send_analytics_event(
src/fidesops/analytics.py:43: in send_analytics_event
    analytics_client.send(event)
/usr/local/lib/python3.9/site-packages/fideslog/sdk/python/client.py:88: in send
    run(self.__send(event))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

main = <coroutine object AnalyticsClient.__send at 0x4031765ac0>

    def run(main, *, debug=None):
        """Execute the coroutine and return the result.
    
        This function runs the passed coroutine, taking care of
        managing the asyncio event loop and finalizing asynchronous
        generators.
    
        This function cannot be called when another asyncio event loop is
        running in the same thread.
    
        If debug is True, the event loop will be run in debug mode.
    
        This function always creates a new event loop and closes it at the end.
        It should be used as a main entry point for asyncio programs, and should
        ideally only be called once.
    
        Example:
    
            async def main():
                await asyncio.sleep(1)
                print('hello')
    
            asyncio.run(main())
        """
        if events._get_running_loop() is not None:
>           raise RuntimeError(
                "asyncio.run() cannot be called from a running event loop")
E           RuntimeError: asyncio.run() cannot be called from a running event loop


Steps to Reproduce

  1. Do this...
  2. Then This...

Expected behavior

A description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • Version:
  • OS:
  • Python Version:
  • Docker Version:

Additional context

Add any other context about the problem here.

@pattisdr pattisdr added the bug Something isn't working label Jun 30, 2022
@PSalant726
Copy link
Contributor

@pattisdr can you please provide more context in the issue description? What is the usage of the .send() method in your codebase that's causing this exception to be raised? How can I reproduce this?

@pattisdr
Copy link
Author

pattisdr commented Jul 5, 2022

@PSalant726, this wasn't calling out a specific usage per se, just if the fidesops API encounters an unhandled exception, this is the trace you will get now, instead of the actual exception. So I see this now during development when I'm working out my edge cases, but users can get 500's too if they stumble onto something we haven't handled.

To duplicate, I'd take any fidesops endpoint, add {}["hi"] anywhere in the view to force a KeyError, and then ping that endpoint and check your fidesops container.

This was referenced Aug 28, 2022
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

Successfully merging a pull request may close this issue.

2 participants