Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend connect timeout #750

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions documentation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ When no value or 0 is provided `1000 * (keepalive + keepalive_keep_interval * ke

`keepalive_usr_timeout 7`

### backend_connect_timeout_ms *integer*
Timeout for connection to backend (postgres). Default value is 30000 (30 secs)

`backend_connect_timeout_ms 20000`

#### coroutine\_stack\_size *integer*

Coroutine stack size.
Expand Down
5 changes: 5 additions & 0 deletions odyssey.conf
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ keepalive_probes 9
#
keepalive_usr_timeout 0

#
# Timeout for connection to backend in ms
#
backend_connect_timeout_ms 20000

###
### GLOBAL LIMITS
###
Expand Down
4 changes: 3 additions & 1 deletion sources/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ static inline int od_backend_connect_to(od_server_t *server, char *context,
}

/* connect to server */
rc = machine_connect(server->io.io, saddr, 1000);
rc = machine_connect(
server->io.io, saddr,
(uint32_t)instance->config.backend_connect_timeout_ms);
if (ai) {
freeaddrinfo(ai);
}
Expand Down
6 changes: 6 additions & 0 deletions sources/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ void od_config_init(od_config_t *config)
config->hba_file = NULL;
config->group_checker_interval = 7000; // 7 seconds
od_list_init(&config->listen);

config->backend_connect_timeout_ms = 30U * 1000U; // 30 seconds
}

void od_config_reload(od_config_t *current_config, od_config_t *new_config)
Expand All @@ -66,6 +68,8 @@ void od_config_reload(od_config_t *current_config, od_config_t *new_config)
current_config->client_max = new_config->client_max;
current_config->client_max_routing = new_config->client_max_routing;
current_config->server_login_retry = new_config->server_login_retry;
current_config->backend_connect_timeout_ms =
new_config->backend_connect_timeout_ms;
}

static void od_config_listen_free(od_config_listen_t *);
Expand Down Expand Up @@ -309,6 +313,8 @@ void od_config_print(od_config_t *config, od_logger_t *logger)
config->workers);
od_log(logger, "config", NULL, NULL, "resolvers %d",
config->resolvers);
od_log(logger, "config", NULL, NULL, "backend_connect_timeout_ms %u",
config->backend_connect_timeout_ms);

if (config->enable_online_restart_feature) {
od_log(logger, "config", NULL, NULL,
Expand Down
2 changes: 2 additions & 0 deletions sources/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ struct od_config {
// Soft interval between group checks
int group_checker_interval;
od_list_t listen;

int backend_connect_timeout_ms;
};

void od_config_init(od_config_t *);
Expand Down
13 changes: 13 additions & 0 deletions sources/config_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef enum {
OD_LCLIENT_FWD_ERROR,
OD_LPRESERVE_SESSION_SERVER_CONN,
OD_LAPPLICATION_NAME_ADD_HOST,
OD_LBACKEND_CONNECT_TIMEOUT_MS,
OD_LSERVER_LIFETIME,
OD_LTLS,
OD_LTLS_CA_FILE,
Expand Down Expand Up @@ -227,6 +228,9 @@ static od_keyword_t od_config_keywords[] = {
od_keyword("application_name_add_host", OD_LAPPLICATION_NAME_ADD_HOST),
od_keyword("server_lifetime", OD_LSERVER_LIFETIME),

od_keyword("backend_connect_timeout_ms",
OD_LBACKEND_CONNECT_TIMEOUT_MS),

/* tls */
od_keyword("tls", OD_LTLS),
od_keyword("tls_ca_file", OD_LTLS_CA_FILE),
Expand Down Expand Up @@ -2637,6 +2641,15 @@ static int od_config_reader_parse(od_config_reader_t *reader,
}
continue;

/* backend_connect_timeout_ms */
case OD_LBACKEND_CONNECT_TIMEOUT_MS:
if (!od_config_reader_number(
reader,
&config->backend_connect_timeout_ms)) {
goto error;
}
continue;

/* keepalive_usr_timeout */
case OD_LKEEPALIVE_USR_TIMEOUT:
if (!od_config_reader_number(
Expand Down
27 changes: 10 additions & 17 deletions sources/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,21 +1082,17 @@ static inline int od_console_show_servers_server_cb(od_server_t *server,
return 0;
}


static inline int od_console_show_fds_server_cb(od_server_t *server,
void **argv)
void **argv)
{
od_route_t *route = server->route;

int offset;
int offset;
int mmask;
machine_msg_t *stream = argv[0];
machine_msg_t *msg;
msg = kiwi_be_write_data_row(stream, &offset);
if (msg == NULL)
return NOT_OK_RESPONSE;


/* type */
char data[64];
size_t data_len;
Expand All @@ -1114,23 +1110,23 @@ static inline int od_console_show_fds_server_cb(od_server_t *server,
if (rc == NOT_OK_RESPONSE)
return NOT_OK_RESPONSE;
/* system fd */
data_len =
od_snprintf(data, sizeof(data), "%d", machine_io_sysfd(server->io.io));
data_len = od_snprintf(data, sizeof(data), "%d",
machine_io_sysfd(server->io.io));
rc = kiwi_be_write_data_row_add(msg, offset, data, data_len);
if (rc == NOT_OK_RESPONSE)
return NOT_OK_RESPONSE;
/* machine fd mask */
mmask = machine_io_sysfd(server->io.io);
data_len =
od_snprintf(data, sizeof(data), "%s/%s", mmask & 1 ? "R" : "NOR", mmask & 2 ? "W" : "NOW");
od_snprintf(data, sizeof(data), "%s/%s",
mmask & 1 ? "R" : "NOR", mmask & 2 ? "W" : "NOW");
rc = kiwi_be_write_data_row_add(msg, offset, data, data_len);
if (rc == NOT_OK_RESPONSE)
return NOT_OK_RESPONSE;

return 0;
}


static inline int od_console_show_server_prep_stmt_cb(od_server_t *server,
void **argv)
{
Expand Down Expand Up @@ -1238,7 +1234,6 @@ static inline int od_console_show_servers_cb(od_route_t *route, void **argv)
return 0;
}


static inline int od_console_show_fds_cb(od_route_t *route, void **argv)
{
od_route_lock(route);
Expand All @@ -1253,7 +1248,6 @@ static inline int od_console_show_fds_cb(od_route_t *route, void **argv)
return 0;
}


static inline int od_console_show_server_prep_stmts_cb(od_route_t *route,
void **argv)
{
Expand Down Expand Up @@ -1290,16 +1284,15 @@ static inline int od_console_show_servers(od_client_t *client,
return kiwi_be_write_complete(stream, "SHOW", 5);
}


static inline int od_console_show_fds(od_client_t *client,
machine_msg_t *stream)
machine_msg_t *stream)
{
assert(stream);
od_router_t *router = client->global->router;

machine_msg_t *msg;
msg = kiwi_be_write_row_descriptionf(
stream, "ssds", "type", "ptr", "machine fd", "machine fd mask");
msg = kiwi_be_write_row_descriptionf(stream, "ssds", "type", "ptr",
"machine fd", "machine fd mask");
if (msg == NULL)
return NOT_OK_RESPONSE;

Expand Down
12 changes: 6 additions & 6 deletions third_party/machinarium/sources/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
#include <machinarium.h>
#include <machinarium_private.h>



MACHINE_API int machine_io_sysfd(machine_io_t *obj) {
MACHINE_API int machine_io_sysfd(machine_io_t *obj)
{
mm_io_t *io = mm_cast(mm_io_t *, obj);
return io->fd;
}

MACHINE_API int machine_io_mask(machine_io_t *obj) {
MACHINE_API int machine_io_mask(machine_io_t *obj)
{
mm_io_t *io = mm_cast(mm_io_t *, obj);
return io->handle.mask;
}


MACHINE_API int machine_io_mm_fd(machine_io_t *obj) {
MACHINE_API int machine_io_mm_fd(machine_io_t *obj)
{
mm_io_t *io = mm_cast(mm_io_t *, obj);
return io->handle.fd;
}