(Merge 3.2) Issue #12133: fix a ResourceWarning in urllib.request

AbstractHTTPHandler.do_open() of urllib.request closes the HTTP connection if
its getresponse() method fails with a socket error. Patch written by Ezio
Melotti.
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index 8cd5ca0..d19e116 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -318,6 +318,9 @@
     def getresponse(self):
         return MockHTTPResponse(MockFile(), {}, 200, "OK")
 
+    def close(self):
+        pass
+
 class MockHandler:
     # useful for testing handler machinery
     # see add_ordered_mock_handlers() docstring
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index e98a976..316e0f9 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1146,6 +1146,8 @@
             r = h.getresponse()  # an HTTPResponse instance
         except socket.error as err:
             raise URLError(err)
+        finally:
+            h.close()
 
         r.url = req.get_full_url()
         # This line replaces the .msg attribute of the HTTPResponse
diff --git a/Misc/NEWS b/Misc/NEWS
index 38850c7..630b890 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -193,6 +193,10 @@
 Library
 -------
 
+- Issue #12133: AbstractHTTPHandler.do_open() of urllib.request closes the HTTP
+  connection if its getresponse() method fails with a socket error. Patch
+  written by Ezio Melotti.
+
 - Issue #12240: Allow multiple setup hooks in packaging's setup.cfg files.
   Original patch by Erik Bray.