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
84 | 84 | self.path = path |
85 | 85 | |
86 | 86 | |
87 | def http_response_iterator(f, size): | |
87 | def http_response_iterator(conn, size): | |
88 | 88 | """ |
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 | |
90 | 93 | """ |
91 | chunk = f.read(size) | |
94 | response = conn.getresponse() | |
95 | chunk = response.read(size) | |
92 | 96 | while chunk: |
93 | 97 | yield chunk |
94 | chunk = f.read(size) | |
98 | chunk = response.read(size) | |
99 | conn.close() | |
95 | 100 | |
96 | 101 | |
97 | 102 | class Store(glance.store.base.Store): |
114 | 119 | conn = conn_class(loc.netloc) |
115 | 120 | conn.request("GET", loc.path, "", {}) |
116 | 121 | |
117 | try: | |
118 | return http_response_iterator(conn.getresponse(), self.CHUNKSIZE) | |
119 | finally: | |
120 | conn.close() | |
122 | return http_response_iterator(conn, self.CHUNKSIZE) | |
121 | 123 | |
122 | 124 | def _get_conn_class(self, loc): |
123 | 125 | """ |