diff --git a/locator/azure_snitch.cc b/locator/azure_snitch.cc index 062ec78f83..a3e78d8d53 100644 --- a/locator/azure_snitch.cc +++ b/locator/azure_snitch.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,8 @@ future azure_snitch::azure_api_call(sstring path) { connected_socket sd(connect(socket_address(a, 80)).get0()); input_stream in(sd.input()); output_stream out(sd.output()); + auto close_in = deferred_close(in); + auto close_out = deferred_close(out); sstring request(seastar::format("GET {} HTTP/1.1\r\nHost: {}\r\nMetadata: True\r\n\r\n", path, AZURE_SERVER_ADDR)); out.write(request).get(); @@ -99,13 +102,7 @@ future azure_snitch::azure_api_call(sstring path) { // Read HTTP response body temporary_buffer buf = in.read_exactly(content_len).get0(); - sstring res(buf.get(), buf.size()); - - // Close streams - out.close().get(); - in.close().get(); - - return res; + return sstring(buf.get(), buf.size()); }); } diff --git a/locator/gce_snitch.cc b/locator/gce_snitch.cc index eff406bbaa..ced370d5ee 100644 --- a/locator/gce_snitch.cc +++ b/locator/gce_snitch.cc @@ -12,6 +12,7 @@ #include #include "locator/gce_snitch.hh" #include +#include #include #include @@ -84,6 +85,8 @@ future gce_snitch::gce_api_call(sstring addr, sstring cmd) { connected_socket sd(connect(socket_address(a, 80)).get0()); input_stream in(sd.input()); output_stream out(sd.output()); + auto close_in = deferred_close(in); + auto close_out = deferred_close(out); sstring zone_req(seastar::format("GET {} HTTP/1.1\r\nHost: metadata\r\nMetadata-Flavor: Google\r\n\r\n", cmd)); out.write(zone_req).get(); @@ -117,10 +120,6 @@ future gce_snitch::gce_api_call(sstring addr, sstring cmd) { std::vector splits; split(splits, res, is_any_of("/")); - // Close streams - out.close().get(); - in.close().get(); - return sstring(splits[splits.size() - 1]); }); }