Skip to content

Commit 923d6d7

Browse files
committed
[vdk-plugins] vdk-kerberos-auth: Separate async event loop
The minikerberos authenticator relies on an async kerberos client to speed up some of its processes. This client uses `asyncio.run()` to execute async operations. As can be seen from the source code of asyncio, https://github.com/python/cpython/blob/3.10/Lib/asyncio/runners.py, the `run()` method creates a new event loop and sets it as the [default loop](https://github.com/python/cpython/blob/3.10/Lib/asyncio/runners.py#L41). When all async operations are finished, the loop it terminated and all tasks are cleaned. This is fine in general, as long as other components don't rely on the main event loop. If they do, however, we could end up in a situation, where the kerberos plugin closes the asyncio main event loop, and breaks the other components that rely on the same thread. To avoid issues with multiple components relying on the asyncio main event loop, this change introduces a separate event loop for the minikerberos authenticator, thus keeping kerberos operations away of the main event loop. Testing done: Functional test added. Signed-off-by: Andon Andonov <andonova@vmware.com>
1 parent 303cd2c commit 923d6d7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

projects/vdk-plugins/vdk-kerberos-auth/src/vdk/plugin/kerberos/minikerberos_authenticator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ def _kinit(self) -> None:
7575
async def get_tgt():
7676
await krb_client.get_TGT()
7777

78-
asyncio.run(get_tgt())
78+
# Create a separate event loop to avoid interfering with users'
79+
# data jobs utilizing asyncio, as well.
80+
loop = asyncio.new_event_loop()
81+
loop.run_until_complete(get_tgt())
82+
loop.close()
83+
7984
krb_client.ccache.to_file(self._ccache_file)
8085
log.info(
8186
f"Got Kerberos TGT for {self._kerberos_principal}@{self._kerberos_realm} "
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2021 VMware, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
import asyncio
4+
import logging
5+
6+
from vdk.api.job_input import IJobInput
7+
8+
log = logging.getLogger(__name__)
9+
10+
11+
def run(job_input: IJobInput):
12+
log.info("Test Async step")
13+
_ = asyncio.Semaphore(2)

0 commit comments

Comments
 (0)