Skip to content

Commit 813e93e

Browse files
committed
[vdk-plugins] vdk-kerberos-auth: Separate async event loop
The `VdkAioKerberosClient` implementation that we currently have, utilizes async/await constructs to speed up some operations. The minikerberos authenticator is the only client that uses the aforementioned async kerberos client. It uses `asyncio.run()` to execute the async operations, which works with the asyncio main thread. This is fine in general, as long as other components don't use async/await. 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 race conditions and other issues with the asyncio thread, this change introduces a separate event loop for the minikerberos authenticator. Testing done: Functional test added. Signed-off-by: Andon Andonov <andonova@vmware.com>
1 parent 7345c14 commit 813e93e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
async def test_method():
12+
await asyncio.sleep(1)
13+
14+
15+
def run(job_input: IJobInput):
16+
log.info("Test Async step")
17+
asyncio.run(test_method())

0 commit comments

Comments
 (0)