Backporing the fix from Issue #12692
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index a7445d1..ef62acc 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1251,6 +1251,12 @@
             raise URLError(err)
         else:
             r = h.getresponse()
+            # If the server does not send us a 'Connection: close' header,
+            # HTTPConnection assumes the socket should be left open. Manually
+            # mark the socket to be closed when this response object goes away.
+            if h.sock:
+                h.sock.close()
+                h.sock = None
 
         r.url = req.get_full_url()
         # This line replaces the .msg attribute of the HTTPResponse