File tree Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Expand file tree Collapse file tree 3 files changed +17
-0
lines changed Original file line number Diff line number Diff line change
1
+ Raise exception for HTTPResponse.shutdown on a connection already released to the pool.
Original file line number Diff line number Diff line change @@ -1100,6 +1100,10 @@ def readable(self) -> bool:
1100
1100
def shutdown (self ) -> None :
1101
1101
if not self ._sock_shutdown :
1102
1102
raise ValueError ("Cannot shutdown socket as self._sock_shutdown is not set" )
1103
+ if self ._connection is None :
1104
+ raise RuntimeError (
1105
+ "Cannot shutdown as connection has already been released to the pool"
1106
+ )
1103
1107
self ._sock_shutdown (socket .SHUT_RD )
1104
1108
1105
1109
def close (self ) -> None :
Original file line number Diff line number Diff line change @@ -912,6 +912,18 @@ def test_cleanup_on_connection_error(self) -> None:
912
912
# the pool should still contain poolsize elements
913
913
assert http .pool .qsize () == http .pool .maxsize
914
914
915
+ def test_shutdown_on_connection_released_to_pool (self ) -> None :
916
+ with HTTPConnectionPool (self .host , self .port ) as pool :
917
+ resp = pool .urlopen ("GET" , "/" , preload_content = False )
918
+ resp .drain_conn ()
919
+ resp .release_conn ()
920
+
921
+ with pytest .raises (
922
+ RuntimeError ,
923
+ match = "Cannot shutdown as connection has already been released to the pool" ,
924
+ ):
925
+ resp .shutdown ()
926
+
915
927
def test_mixed_case_hostname (self ) -> None :
916
928
with HTTPConnectionPool ("LoCaLhOsT" , self .port ) as pool :
917
929
response = pool .request ("GET" , f"http://LoCaLhOsT:{ self .port } /" )
You can’t perform that action at this time.
0 commit comments