Implement login timeout

This commit is contained in:
Andrey Borodin 2019-12-01 23:21:23 +05:00 committed by reshke
parent f43ac71d26
commit eb7299748d
17 changed files with 37 additions and 24 deletions

View File

@ -292,6 +292,10 @@ listen {
# tls_key_file ""
# tls_cert_file ""
# tls_protocols ""
# client_login_timeout
# Prevent client stall during routing for more that client_login_timeout milliseconds.
# Defaults to 15000.
}
###

View File

@ -95,6 +95,7 @@ od_config_listen_add(od_config_t *config)
memset(listen, 0, sizeof(*listen));
listen->port = 6432;
listen->backlog = 128;
listen->client_login_timeout = 15000;
od_list_init(&listen->link);
od_list_append(&config->listen, &listen->link);
return listen;

View File

@ -30,6 +30,7 @@ struct od_config_listen
char *tls_key_file;
char *tls_cert_file;
char *tls_protocols;
int client_login_timeout;
od_list_t link;
};

View File

@ -65,6 +65,7 @@ enum
OD_LCOROUTINE_STACK_SIZE,
OD_LCLIENT_MAX,
OD_LCLIENT_MAX_ROUTING,
OD_LCLIENT_LOGIN_TIMEOUT,
OD_LCLIENT_FWD_ERROR,
OD_LTLS,
OD_LTLS_CA_FILE,
@ -150,6 +151,7 @@ od_config_keywords[] =
od_keyword("coroutine_stack_size", OD_LCOROUTINE_STACK_SIZE),
od_keyword("client_max", OD_LCLIENT_MAX),
od_keyword("client_max_routing", OD_LCLIENT_MAX_ROUTING),
od_keyword("client_login_timeout", OD_LCLIENT_LOGIN_TIMEOUT),
od_keyword("client_fwd_error", OD_LCLIENT_FWD_ERROR),
od_keyword("tls", OD_LTLS),
od_keyword("tls_ca_file", OD_LTLS_CA_FILE),
@ -414,6 +416,11 @@ od_config_reader_listen(od_config_reader_t *reader)
if (! od_config_reader_number(reader, &listen->port))
return -1;
continue;
/* client_login_timeout */
case OD_LCLIENT_LOGIN_TIMEOUT:
if (! od_config_reader_number(reader, &listen->client_login_timeout))
return -1;
continue;
/* backlog */
case OD_LBACKLOG:
if (! od_config_reader_number(reader, &listen->backlog))

View File

@ -107,7 +107,7 @@ od_frontend_startup(od_client_t *client)
od_instance_t *instance = client->global->instance;
machine_msg_t *msg;
msg = od_read_startup(&client->io, UINT32_MAX);
msg = od_read_startup(&client->io, client->config_listen->client_login_timeout);
if (msg == NULL)
goto error;
@ -132,7 +132,7 @@ od_frontend_startup(od_client_t *client)
/* read startup-cancel message followed after ssl
* negotiation */
assert(client->startup.is_ssl_request);
msg = od_read_startup(&client->io, UINT32_MAX);
msg = od_read_startup(&client->io, client->config_listen->client_login_timeout);
if (msg == NULL)
return -1;
rc = kiwi_be_read_startup(machine_msg_data(msg),

View File

@ -104,7 +104,7 @@ od_tls_frontend_accept(od_client_t *client,
od_io_error(&client->io));
return -1;
}
rc = machine_set_tls(client->io.io, tls);
rc = machine_set_tls(client->io.io, tls, config->client_login_timeout);
if (rc == -1) {
od_error(logger, "tls", client, NULL, "error: %s",
od_io_error(&client->io));
@ -203,7 +203,7 @@ od_tls_backend_connect(od_server_t *server,
case 'S':
/* supported */
od_debug(logger, "tls", NULL, server, "supported");
rc = machine_set_tls(server->io.io, server->tls);
rc = machine_set_tls(server->io.io, server->tls, UINT32_MAX);
if (rc == -1) {
od_error(logger, "tls", NULL, server, "error: %s",
od_io_error(&server->io));

View File

@ -37,7 +37,7 @@ server(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,0);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);
@ -91,7 +91,7 @@ client(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,1);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);

View File

@ -36,7 +36,7 @@ server(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,0);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);
@ -96,7 +96,7 @@ client(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,1);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);

View File

@ -36,7 +36,7 @@ server(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,0);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);
@ -96,7 +96,7 @@ client(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,1);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);

View File

@ -36,7 +36,7 @@ server(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,0);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);
@ -90,7 +90,7 @@ client(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,1);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);

View File

@ -35,7 +35,7 @@ server(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,0);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);
@ -94,7 +94,7 @@ client(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,1);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);

View File

@ -37,7 +37,7 @@ server(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,0);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);
@ -103,7 +103,7 @@ client(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,1);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);

View File

@ -39,7 +39,7 @@ server(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,0);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);
@ -94,7 +94,7 @@ client(void *arg)
test(rc == 0);
rc = machine_tls_create_context(tls,1);
test(rc == 0);
rc = machine_set_tls(client, tls);
rc = machine_set_tls(client, tls, UINT32_MAX);
if (rc == -1) {
printf("%s\n", machine_error(client));
test(rc == 0);

View File

@ -257,7 +257,7 @@ machine_tls_set_key_file(machine_tls_t *obj, char *path)
}
MACHINE_API int
machine_set_tls(machine_io_t *obj, machine_tls_t *tls)
machine_set_tls(machine_io_t *obj, machine_tls_t *tls, uint32_t timeout)
{
mm_io_t *io = mm_cast(mm_io_t*, obj);
if (io->tls) {
@ -265,7 +265,7 @@ machine_set_tls(machine_io_t *obj, machine_tls_t *tls)
return -1;
}
io->tls = mm_cast(mm_tls_t*, tls);
return mm_tls_handshake(io);
return mm_tls_handshake(io, timeout);
}
MACHINE_API machine_io_t*

View File

@ -242,7 +242,7 @@ MACHINE_API int
machine_set_keepalive(machine_io_t*, int enable, int delay);
MACHINE_API int
machine_set_tls(machine_io_t*, machine_tls_t*);
machine_set_tls(machine_io_t*, machine_tls_t*, uint32_t);
MACHINE_API int
machine_io_verify(machine_io_t*, char *common_name);

View File

@ -354,7 +354,7 @@ done:
}
int
mm_tls_handshake(mm_io_t *io)
mm_tls_handshake(mm_io_t *io, uint32_t timeout)
{
mm_machine_t *machine = mm_self;
mm_tls_error_reset(io);
@ -373,7 +373,7 @@ mm_tls_handshake(mm_io_t *io)
}
/* wait for completion */
mm_call(&io->call, MM_CALL_HANDSHAKE, UINT32_MAX);
mm_call(&io->call, MM_CALL_HANDSHAKE, timeout);
rc = mm_loop_read_write_stop(&machine->loop, &io->handle);
if (rc == -1) {

View File

@ -18,7 +18,7 @@ mm_tls_is_active(mm_io_t *io) {
void mm_tls_init(mm_io_t*);
void mm_tls_free(mm_io_t*);
void mm_tls_error_reset(mm_io_t*);
int mm_tls_handshake(mm_io_t*);
int mm_tls_handshake(mm_io_t*, uint32_t);
int mm_tls_write(mm_io_t*, char*, int);
int mm_tls_writev(mm_io_t*, struct iovec*, int);
int mm_tls_read_pending(mm_io_t*);