Skip to content

Commit 829101d

Browse files
authored
Fix urllib bug in vendored library (#1785)
* Fix urllib bug in vendored library * changelog updates
1 parent 2851d3b commit 829101d

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1515
- Added the `backoff_policy` argument to `snowflake.connector.connect` allowing for configurable backoff policy between retries of failed requests. See available implementations in the `backoff_policies` module.
1616
- Added the `socket_timeout` argument to `snowflake.connector.connect` specifying socket read and connect timeout.
1717
- Fixed `login_timeout` and `network_timeout` behaviour. Retries of login and network requests are now properly halted after these timeouts expire.
18+
- Fixed bug for issue https://github.com/urllib3/urllib3/issues/1878 in vendored `urllib`.
1819

1920
- v3.3.1(October 16,2023)
2021

src/snowflake/connector/vendored/urllib3/util/connection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def is_connection_dropped(conn): # Platform-specific
2323
return False
2424
if sock is None: # Connection already closed (such as by httplib).
2525
return True
26+
# See issue for more context: https://github.com/urllib3/urllib3/issues/1878
27+
# the maintainers know that this issue can be resolve using the change below but
28+
# they have not merged this change because they need to root-cause it. See
29+
# comment: https://github.com/urllib3/urllib3/issues/1878#issuecomment-641548977
30+
# adding the fix in our vendored code so our users get unblocked
31+
if getattr(sock, "fileno", lambda _: None)() == -1:
32+
return True
2633
try:
2734
# Returns True if readable, which here means it's been dropped
2835
return wait_for_read(sock, timeout=0.0)

test/integ/test_vendored_urllib.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
4+
#
5+
6+
import pytest
7+
8+
try:
9+
from snowflake.connector.vendored import urllib3
10+
11+
vendored_imported = True
12+
except ModuleNotFoundError:
13+
vendored_imported = False
14+
15+
16+
@pytest.mark.skipif(
17+
not vendored_imported, reason="vendored library is not imported for old driver"
18+
)
19+
def test_local_fix_for_closed_socket_bug():
20+
# https://github.com/urllib3/urllib3/issues/1878#issuecomment-641534573
21+
http = urllib3.PoolManager(maxsize=1)
22+
23+
def _execute_request():
24+
resp = http.request(
25+
method="GET", url="http://httpbin.org", preload_content=False
26+
)
27+
resp._connection.sock.close()
28+
resp.release_conn()
29+
resp.close()
30+
return resp
31+
32+
_execute_request()
33+
try:
34+
_execute_request()
35+
except ValueError as e:
36+
if "file descriptor cannot be a negative" in str(e):
37+
raise AssertionError(
38+
"Second _execute_request failed. See linked github issue comment"
39+
)
40+
else:
41+
raise e

0 commit comments

Comments
 (0)