From 5864bd067c434ea96b59fec67f1f6b39e8178bc3 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 12 Nov 2024 02:23:25 +0300 Subject: [PATCH] Add missing connection timeout for etcd websockets in OSD --- src/client/http_client.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/client/http_client.cpp b/src/client/http_client.cpp index 4b60c645..1001c570 100644 --- a/src/client/http_client.cpp +++ b/src/client/http_client.cpp @@ -62,6 +62,7 @@ struct http_co_t inline void end() { ended = true; if (!onstack) { delete this; } } void run_cb_and_clear(); void start_connection(); + void start_ws_connection(); void close_connection(); void next_request(); void handle_events(); @@ -112,7 +113,7 @@ http_co_t* open_websocket(timerfd_manager_t *tfd, const std::string & host, cons handler->keepalive = false; handler->request = request; handler->response_callback = response_callback; - handler->start_connection(); + handler->start_ws_connection(); return handler; } @@ -282,6 +283,27 @@ void http_co_t::close_connection() epoll_events = 0; } +void http_co_t::start_ws_connection() +{ + stackin(); + start_connection(); + if (request_timeout > 0) + { + timeout_id = tfd->set_timer(request_timeout, false, [this](int timer_id) + { + stackin(); + if (state != HTTP_CO_WEBSOCKET) + { + close_connection(); + parsed = { .error = "Websocket connection timed out" }; + run_cb_and_clear(); + } + stackout(); + }); + } + stackout(); +} + void http_co_t::start_connection() { stackin();