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

use session to build client - to be threadsafe #195

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dbt/adapters/glue/gluedbapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dbt.adapters.glue.credentials import GlueCredentials
from dbt.adapters.glue.gluedbapi.commons import GlueStatement
import time
import threading
import uuid
from dbt.events import AdapterLogger

Expand All @@ -23,6 +24,7 @@ class GlueSessionState:

@dataclass
class GlueConnection:
_boto3_client_lock = threading.Lock()

def __init__(self, credentials: GlueCredentials, session_id: str = None):
self.credentials = credentials
Expand Down Expand Up @@ -140,7 +142,10 @@ def client(self):
}
)
if not self._client:
self._client = boto3.client("glue", region_name=self.credentials.region, config=config)
# refernce on why lock is required - https://stackoverflow.com/a/61943955/6034432
with self._boto3_client_lock:
session = boto3.session.Session()
self._client = session.client("glue", region_name=self.credentials.region, config=config)
return self._client

def cancel_statement(self, statement_id):
Expand Down