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

vdk-kerberos-auth: enable auth to work inside a running asyncio event loop #2600

Merged
merged 2 commits into from
Aug 24, 2023

Conversation

antoniivanov
Copy link
Collaborator

@antoniivanov antoniivanov commented Aug 23, 2023

This change adds _run_coroutine function to ensure proper execution of a get_tgt coroutine, even if called within an already running event loop in asyncio (which in principal is not allowed)

This is happening when the plugin is invoked within a jupyter notebook which runs within a async event loop started by tornado server. And this causes following errors:

Traceback (most recent call last):
File
"/opt/conda/lib/python3.7/site-packages/vdk/plugin/kerberos/minikerberos_authenticator.py",
line 90, in _kinit
    loop.run_until_complete(get_tgt())
File "/opt/conda/lib/python3.7/asyncio/base_events.py", line 563, in
run_until_complete
    self._check_runnung()
File "/opt/conda/lib/python3.7/asyncio/base_events.py", line 526, in
_check_runnung
    'Cannot run the event loop while another loop is running')
RuntimeError: Cannot run the event loop while another loop is running

The way the fix works is

  • If the current event loop is running, the function now starts a new thread to run the coroutine, ensuring that it runs to completion without conflict with the existing loop.
  • Otherwise it creates a new asyncio event loop in the current thread and runs the couritine as before.

@antoniivanov antoniivanov changed the title vdk-kerberos-auth: enable authentication to work inside a running asy… vdk-kerberos-auth: enable auth to work inside a running asyncio event loop Aug 23, 2023
…nc event loop

This change adds _run_coroutine function to ensure proper execution of a
get_tgt coroutine, even if called within an already running event loop
in asyncio (which in principal is not allowed)

This is happening when the plugin is invoked within a jupyter notebook
which runs within a async event loop started by tornado server.
And this causes following errors:
```
Traceback (most recent call last):
File
"/opt/conda/lib/python3.7/site-packages/vdk/plugin/kerberos/minikerberos_authenticator.py",
line 90, in _kinit
    loop.run_until_complete(get_tgt())
File "/opt/conda/lib/python3.7/asyncio/base_events.py", line 563, in
run_until_complete
    self._check_runnung()
File "/opt/conda/lib/python3.7/asyncio/base_events.py", line 526, in
_check_runnung
    'Cannot run the event loop while another loop is running')
RuntimeError: Cannot run the event loop while another loop is running
```

The way the fix works is
- If the current event loop is running, the function now starts a new
thread to run the coroutine, ensuring that it runs to completion without
conflict with the existing loop.
- Otherwise it creates a new asyncio event loop in the current thread
and runs the couritine as before.
Copy link
Collaborator

@duyguHsnHsn duyguHsnHsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@antoniivanov antoniivanov merged commit e9cbbe9 into main Aug 24, 2023
10 of 11 checks passed
@antoniivanov antoniivanov deleted the person/aivanov/vdk-kerberos branch August 24, 2023 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants