File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
drift/instrumentation/urllib3/e2e-tests/src Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -223,19 +223,23 @@ def poolmanager_chain():
223223@app .route ("/api/connectionpool/get-json" , methods = ["GET" ])
224224def connectionpool_get_json ():
225225 """Test GET request using HTTPConnectionPool directly."""
226+ pool = None
226227 try :
227228 pool = urllib3 .HTTPSConnectionPool ("jsonplaceholder.typicode.com" , port = 443 )
228229 response = pool .request ("GET" , "/posts/2" )
229230 data = json .loads (response .data .decode ("utf-8" ))
230- pool .close ()
231231 return jsonify (data )
232232 except Exception as e :
233233 return jsonify ({"error" : str (e )}), 500
234+ finally :
235+ if pool is not None :
236+ pool .close ()
234237
235238
236239@app .route ("/api/connectionpool/post-json" , methods = ["POST" ])
237240def connectionpool_post_json ():
238241 """Test POST request using HTTPConnectionPool directly."""
242+ pool = None
239243 try :
240244 req_data = request .get_json () or {}
241245 body = json .dumps (
@@ -253,10 +257,12 @@ def connectionpool_post_json():
253257 headers = {"Content-Type" : "application/json" },
254258 )
255259 data = json .loads (response .data .decode ("utf-8" ))
256- pool .close ()
257260 return jsonify (data ), 201
258261 except Exception as e :
259262 return jsonify ({"error" : str (e )}), 500
263+ finally :
264+ if pool is not None :
265+ pool .close ()
260266
261267
262268# =============================================================================
You can’t perform that action at this time.
0 commit comments