Skip to content
Snippets Groups Projects
Commit bdd62d40 authored by Grigorii Demidov's avatar Grigorii Demidov Committed by Petr Špaček
Browse files

daemon: make idle timeout for incoming connection configurable

parent a0670f6b
No related branches found
No related tags found
1 merge request!624daemon/io: configurable idle timeout for incoming TCP connection
Pipeline #37831 passed with warnings
......@@ -793,6 +793,37 @@ static int net_outgoing(lua_State *L, int family)
static int net_outgoing_v4(lua_State *L) { return net_outgoing(L, AF_INET); }
static int net_outgoing_v6(lua_State *L) { return net_outgoing(L, AF_INET6); }
static int net_tcp_in_idle(lua_State *L)
{
struct engine *engine = engine_luaget(L);
struct network *net = &engine->net;
/* Only return current idle timeout. */
if (lua_gettop(L) == 0) {
lua_pushnumber(L, net->tcp.in_idle_timeout);
return 1;
}
if ((lua_gettop(L) != 1)) {
lua_pushstring(L, "net.tcp_in_idle takes one parameter: (\"idle timeout\")");
lua_error(L);
}
if (lua_isnumber(L, 1)) {
int idle_timeout = lua_tointeger(L, 1);
if (idle_timeout <= 0) {
lua_pushstring(L, "net.tcp_in_idle parameter has to be positive number");
lua_error(L);
}
net->tcp.in_idle_timeout = idle_timeout;
} else {
lua_pushstring(L, "net.tcp_in_idle parameter has to be positive number");
lua_error(L);
}
lua_pushboolean(L, true);
return 1;
}
int lib_net(lua_State *L)
{
static const luaL_Reg lib[] = {
......@@ -810,6 +841,7 @@ int lib_net(lua_State *L)
{ "tls_sticket_secret_file", net_tls_sticket_secret_file },
{ "outgoing_v4", net_outgoing_v4 },
{ "outgoing_v6", net_outgoing_v6 },
{ "tcp_in_idle", net_tcp_in_idle },
{ NULL, NULL }
};
register_lib(L, "net", lib);
......
......@@ -301,6 +301,11 @@ static void _tcp_accept(uv_stream_t *master, int status, bool tls)
return;
}
const struct worker_ctx *worker = (struct worker_ctx *)master->loop->data;
const struct engine *engine = worker->engine;
const struct network *net = &engine->net;
uint64_t idle_in_timeout = net->tcp.in_idle_timeout;
uint64_t timeout = KR_CONN_RTT_MAX / 2;
session->has_tls = tls;
if (tls) {
......@@ -316,7 +321,7 @@ static void _tcp_accept(uv_stream_t *master, int status, bool tls)
}
}
uv_timer_t *timer = &session->timeout;
uv_timer_start(timer, tcp_timeout_trigger, timeout, timeout);
uv_timer_start(timer, tcp_timeout_trigger, timeout, idle_in_timeout);
io_start_read((uv_handle_t *)client);
}
......
......@@ -54,6 +54,7 @@ void network_init(struct network *net, uv_loop_t *loop)
net->tls_client_params = map_make(NULL);
net->tls_session_ticket_ctx = /* unsync. random, by default */
tls_session_ticket_ctx_create(loop, NULL, 0);
net->tcp.in_idle_timeout = 10000;
}
}
......@@ -112,6 +113,7 @@ void network_deinit(struct network *net)
tls_client_params_free(&net->tls_client_params);
net->tls_credentials = NULL;
tls_session_ticket_ctx_destroy(net->tls_session_ticket_ctx);
net->tcp.in_idle_timeout = 0;
}
}
......
......@@ -42,6 +42,10 @@ struct endpoint {
typedef array_t(struct endpoint*) endpoint_array_t;
/* @endcond */
struct net_tcp_param {
uint64_t in_idle_timeout;
};
struct tls_session_ticket_ctx;
struct network {
uv_loop_t *loop;
......@@ -49,6 +53,7 @@ struct network {
struct tls_credentials *tls_credentials;
map_t tls_client_params;
struct tls_session_ticket_ctx *tls_session_ticket_ctx;
struct net_tcp_param tcp;
};
void network_init(struct network *net, uv_loop_t *loop);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment