Skip to content

Commit

Permalink
Implement login timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
x4m authored and reshke committed Dec 2, 2019
1 parent f43ac71 commit eb72997
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 24 deletions.
4 changes: 4 additions & 0 deletions odyssey.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

###
Expand Down
1 change: 1 addition & 0 deletions sources/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sources/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
7 changes: 7 additions & 0 deletions sources/config_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions sources/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions sources/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions test/machinarium/test_tls0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/machinarium/test_tls_read_10mb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/machinarium/test_tls_read_10mb1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/machinarium/test_tls_read_10mb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/machinarium/test_tls_read_multithread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/machinarium/test_tls_read_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/machinarium/test_tls_unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions third_party/machinarium/sources/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ 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) {
mm_errno_set(EINPROGRESS);
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*
Expand Down
2 changes: 1 addition & 1 deletion third_party/machinarium/sources/machinarium.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions third_party/machinarium/sources/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ mm_tls_handshake_cb(mm_fd_t *handle)
}

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);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion third_party/machinarium/sources/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down

0 comments on commit eb72997

Please sign in to comment.