Codebase list glance / 22e8bf5
Fixes LP Bug #804429 The try: finally: block which called conn.close() in the http store driver was flawed and the connection was not being properly released. This changes the http_response_iterator generator to accept the HTTP connection and close it on final yield. Change-Id: I545a7f5c93ccd196a99b50e8464778e075b549d8 Jay Pipes 12 years ago
1 changed file(s) with 10 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
8484 self.path = path
8585
8686
87 def http_response_iterator(f, size):
87 def http_response_iterator(conn, size):
8888 """
89 Return an iterator for a file-like object
89 Return an iterator for a file-like object.
90
91 :param conn: HTTP(S) Connection
92 :param size: Chunk size to iterate with
9093 """
91 chunk = f.read(size)
94 response = conn.getresponse()
95 chunk = response.read(size)
9296 while chunk:
9397 yield chunk
94 chunk = f.read(size)
98 chunk = response.read(size)
99 conn.close()
95100
96101
97102 class Store(glance.store.base.Store):
114119 conn = conn_class(loc.netloc)
115120 conn.request("GET", loc.path, "", {})
116121
117 try:
118 return http_response_iterator(conn.getresponse(), self.CHUNKSIZE)
119 finally:
120 conn.close()
122 return http_response_iterator(conn, self.CHUNKSIZE)
121123
122124 def _get_conn_class(self, loc):
123125 """