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

reproduce retry attempt #2008

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/snowflake/connector/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def __init__(
self._sessions_map: dict[str | None, SessionPool] = collections.defaultdict(
lambda: SessionPool(self)
)
self._counter = 0

# OCSP mode (OCSPMode.FAIL_OPEN by default)
ssl_wrap_socket.FEATURE_OCSP_MODE = (
Expand Down Expand Up @@ -890,6 +891,11 @@ def _request_exec_wrapper(
token=token,
**kwargs,
)
if method.upper() == 'GET' and "/queries/" in full_url:
if self._counter == 0:
pass
#return_object = None
self._counter += 1
if return_object is not None:
return return_object
self._handle_unknown_error(method, full_url, headers, data, conn)
Expand Down
10 changes: 9 additions & 1 deletion src/snowflake/connector/vendored/urllib3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self, *args, **kw):
# Proxy options provided by the user.
self.proxy = kw.pop("proxy", None)
self.proxy_config = kw.pop("proxy_config", None)

self._counter = 0
_HTTPConnection.__init__(self, *args, **kw)

@property
Expand Down Expand Up @@ -241,7 +241,15 @@ def request(self, method, url, body=None, headers=None):
headers = headers.copy()
if "user-agent" not in (six.ensure_str(k.lower()) for k in headers):
headers["User-Agent"] = _get_default_user_agent()
# this goes to python built in client
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
if method.upper() == 'GET' and "/queries/" in url:
# try immediately close socket here when performing get query request, not waiting for result
# TODO: not sure if this is fast enough to trigger 499 at the backend, check snowhouse traffic if this can trigger 499 error
if self._counter == 1:
self.sock.close()
self._counter = 0
self._counter += 1

def request_chunked(self, method, url, body=None, headers=None):
"""
Expand Down
16 changes: 15 additions & 1 deletion src/snowflake/connector/vendored/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def __init__(
# Close all the HTTPConnections in the pool before the
# HTTPConnectionPool object is garbage collected.
weakref_finalize(self, _close_pool_connections, pool)
self._get_counter = 0

def _new_conn(self):
"""
Expand Down Expand Up @@ -639,7 +640,13 @@ def urlopen(
Additional parameters are passed to
:meth:`urllib3.response.HTTPResponse.from_httplib`
"""

"""
post queries are like the following:
'/queries/v1/query-request?requestId=xxx&request_guid=xxx'
"""
if method == "GET" and url.startswith("/queries/"):
print('urlopen counter', self._get_counter)
self._get_counter += 1
parsed_url = parse_url(url)
destination_scheme = parsed_url.scheme

Expand Down Expand Up @@ -721,6 +728,9 @@ def urlopen(
headers=headers,
chunked=chunked,
)
# attempt 1: mock SocketError, after calling GET query twice, raise the error
if self._get_counter == 2:
raise SocketError("Remote Disconnected")

# If we're going to release the connection in ``finally:``, then
# the response doesn't need to know about the connection. Otherwise
Expand All @@ -740,6 +750,10 @@ def urlopen(
**response_kw
)

# attempt 2: mock raise 499 error
# if self._get_counter == 2:
# response = HTTPResponse(status=499)

# Everything went great!
clean_exit = True

Expand Down
Loading
Loading