Skip to content

Commit

Permalink
http: Fix double call to stop() in http::client
Browse files Browse the repository at this point in the history
- http::client::stop() can be called twice in the event the client is
used via the `with_client` method.

- The method had unconditionally called stop() in a finally clause with
the intention to have users not have to manually do this and forget to
call stop.

- However stop() can also be called within certain exception handlers
within methods invoked by http::client, ones that handle
tls::verification_error exceptions.

- This patch adds a boolean to our http client so that stop() can early
exit if it has already been called.

(cherry picked from commit 2ed203d)
  • Loading branch information
Rob Blafford committed May 29, 2024
1 parent 9e4bddc commit 5baee47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/v/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ ss::future<reconnect_result_t> client::get_connected(
}

ss::future<> client::stop() {
if (_stopped) {
// Prevent double call to stop() as constructs such as with_client()
// will unconditionally call stop(), while exception handlers in this
// file may also call stop()
co_return;
}
_stopped = true;
co_await _connect_gate.close();
// Can safely stop base_transport
co_return co_await base_transport::stop();
Expand Down
1 change: 1 addition & 0 deletions src/v/http/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class client : protected net::base_transport {
/// Throw exception if _as is aborted
void check() const;

bool _stopped{false};
ss::gate _connect_gate;
const ss::abort_source* _as;
ss::shared_ptr<http::client_probe> _probe;
Expand Down

0 comments on commit 5baee47

Please sign in to comment.