Skip to content

Commit 3b2b76b

Browse files
sfc-gh-pbulawasfc-gh-pczajka
authored andcommitted
SNOW-1955965: Fix expired S3 credentials update (#2258)
1 parent acf59cf commit 3b2b76b

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/snowflake/connector/file_transfer_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ def __init__(
319319
def update(self, cur_timestamp) -> None:
320320
with self.lock:
321321
if cur_timestamp < self.timestamp:
322+
logger.debug(
323+
"Omitting renewal of storage token, as it already happened."
324+
)
322325
return
323326
logger.debug("Renewing expired storage token.")
324327
ret = self.connection.cursor()._execute_helper(self._command)
@@ -540,7 +543,7 @@ def transfer_done_cb(
540543
) -> None:
541544
# Note: chunk_id is 0 based while num_of_chunks is count
542545
logger.debug(
543-
f"Chunk {chunk_id}/{done_client.num_of_chunks} of file {done_client.meta.name} reached callback"
546+
f"Chunk(id: {chunk_id}) {chunk_id+1}/{done_client.num_of_chunks} of file {done_client.meta.name} reached callback"
544547
)
545548
with cv_chunk_process:
546549
transfer_metadata.chunks_in_queue -= 1

src/snowflake/connector/s3_storage_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ def generate_authenticated_url_and_args_v4() -> tuple[bytes, dict[str, bytes]]:
333333
amzdate = t.strftime("%Y%m%dT%H%M%SZ")
334334
short_amzdate = amzdate[:8]
335335
x_amz_headers["x-amz-date"] = amzdate
336+
x_amz_headers["x-amz-security-token"] = self.credentials.creds.get(
337+
"AWS_TOKEN", ""
338+
)
336339

337340
(
338341
canonical_request,

src/snowflake/connector/storage_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def _send_request_with_retry(
286286
conn = self.meta.sfagent._cursor.connection
287287

288288
while self.retry_count[retry_id] < self.max_retry:
289+
logger.debug(f"retry #{self.retry_count[retry_id]}")
289290
cur_timestamp = self.credentials.timestamp
290291
url, rest_kwargs = get_request_args()
291292
rest_kwargs["timeout"] = (REQUEST_CONNECTION_TIMEOUT, REQUEST_READ_TIMEOUT)
@@ -299,10 +300,14 @@ def _send_request_with_retry(
299300
response = rest_call(url, **rest_kwargs)
300301

301302
if self._has_expired_presigned_url(response):
303+
logger.debug(
304+
"presigned url expired. trying to update presigned url."
305+
)
302306
self._update_presigned_url()
303307
else:
304308
self.last_err_is_presigned_url = False
305309
if response.status_code in self.TRANSIENT_HTTP_ERR:
310+
logger.debug(f"transient error: {response.status_code}")
306311
time.sleep(
307312
min(
308313
# TODO should SLEEP_UNIT come from the parent
@@ -313,7 +318,9 @@ def _send_request_with_retry(
313318
)
314319
self.retry_count[retry_id] += 1
315320
elif self._has_expired_token(response):
321+
logger.debug("token is expired. trying to update token")
316322
self.credentials.update(cur_timestamp)
323+
self.retry_count[retry_id] += 1
317324
else:
318325
return response
319326
except self.TRANSIENT_ERRORS as e:

0 commit comments

Comments
 (0)