3
3
4
4
#include " util/cloud/gcp/gcs_file.h"
5
5
6
+ #include < absl/cleanup/cleanup.h>
6
7
#include < absl/strings/str_cat.h>
7
8
#include < absl/strings/strip.h>
8
9
@@ -93,7 +94,7 @@ class GcsWriteFile : public detail::AbstractStorageFile {
93
94
GcsWriteFileOptions opts_;
94
95
};
95
96
96
- class GcsReadFile final : public io::ReadonlyFile {
97
+ class GcsReadFile final : public io::ReadonlyFile {
97
98
public:
98
99
// does not own gcs object, only wraps it with ReadonlyFile interface.
99
100
GcsReadFile (string read_obj_url, const GcsReadFileOptions& opts)
@@ -193,7 +194,6 @@ error_code GcsWriteFile::Close() {
193
194
return {};
194
195
}
195
196
196
-
197
197
error_code GcsWriteFile::Upload () {
198
198
size_t body_size = body_mb_.size ();
199
199
CHECK_GT (body_size, 0u );
@@ -317,11 +317,17 @@ io::Result<io::WriteFile*> OpenWriteGcsFile(const string& bucket, const string&
317
317
318
318
RobustSender sender (opts.pool , opts.creds_provider );
319
319
RobustSender::SenderResult send_res;
320
- error_code ec = sender.Send (3 , &empty_req, &send_res);
321
- if (ec) {
320
+ absl::Cleanup cleanup ([&] {
322
321
if (opts.pool_owned ) {
322
+ // We must reset the client handle before deleting the pool that owns it.
323
+ send_res.client_handle .reset ();
323
324
delete opts.pool ;
324
325
}
326
+ });
327
+
328
+ error_code ec = sender.Send (3 , &empty_req, &send_res);
329
+
330
+ if (ec) {
325
331
return nonstd::make_unexpected (ec);
326
332
}
327
333
@@ -330,11 +336,9 @@ io::Result<io::WriteFile*> OpenWriteGcsFile(const string& bucket, const string&
330
336
auto it = headers.find (h2::field::location);
331
337
if (it == headers.end ()) {
332
338
LOG (ERROR) << " Could not find location in " << headers;
333
- if (opts.pool_owned ) {
334
- delete opts.pool ;
335
- }
336
339
return nonstd::make_unexpected (make_error_code (errc::connection_refused));
337
340
}
341
+ std::move (cleanup).Cancel ();
338
342
339
343
return new GcsWriteFile (key, detail::FromBoostSV (it->value ()), opts);
340
344
}
0 commit comments