Skip to content

Commit

Permalink
auth: auth-worker-server: Log errors via events
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and cmouse committed Mar 12, 2021
1 parent 0e06d67 commit 19a40f3
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/auth/auth-worker-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct auth_worker_request {
struct auth_worker_connection {
int fd;

struct event *event;
struct io *io;
struct istream *input;
struct ostream *output;
Expand Down Expand Up @@ -94,7 +95,8 @@ static bool auth_worker_request_send(struct auth_worker_connection *conn,
i_assert(conn->to != NULL);

if (age_secs >= AUTH_WORKER_ABORT_SECS) {
i_error("Aborting auth request that was queued for %d secs, "
e_error(conn->event,
"Aborting auth request that was queued for %d secs, "
"%d left in queue",
age_secs, aqueue_count(worker_request_queue));
request->callback(t_strdup_printf(
Expand All @@ -106,10 +108,10 @@ static bool auth_worker_request_send(struct auth_worker_connection *conn,
ioloop_time - auth_worker_last_warn >
AUTH_WORKER_DELAY_WARN_MIN_INTERVAL_SECS) {
auth_worker_last_warn = ioloop_time;
i_warning("auth workers: Auth request was queued for %d "
"seconds, %d left in queue "
"(see auth_worker_max_count)",
age_secs, aqueue_count(worker_request_queue));
e_error(conn->event, "Auth request was queued for %d "
"seconds, %d left in queue "
"(see auth_worker_max_count)",
age_secs, aqueue_count(worker_request_queue));
}

request->id = ++conn->id_counter;
Expand Down Expand Up @@ -173,20 +175,26 @@ static void auth_worker_send_handshake(struct auth_worker_connection *conn)
static struct auth_worker_connection *auth_worker_create(void)
{
struct auth_worker_connection *conn;
struct event *event;
int fd;

if (array_count(&connections) >= auth_workers_throttle_count)
return NULL;

event = event_create(auth_event);
event_set_append_log_prefix(event, "auth-worker: ");

fd = net_connect_unix_with_retries(worker_socket_path, 5000);
if (fd == -1) {
if (errno == EACCES) {
i_error("%s", eacces_error_get("net_connect_unix",
worker_socket_path));
e_error(event, "%s",
eacces_error_get("net_connect_unix",
worker_socket_path));
} else {
i_error("net_connect_unix(%s) failed: %m",
e_error(event, "net_connect_unix(%s) failed: %m",
worker_socket_path);
}
event_unref(&event);
return NULL;
}

Expand All @@ -198,6 +206,7 @@ static struct auth_worker_connection *auth_worker_create(void)
conn->io = io_add(fd, IO_READ, worker_input, conn);
conn->to = timeout_add(AUTH_WORKER_MAX_IDLE_SECS * 1000,
auth_worker_idle_timeout, conn);
conn->event = event;
auth_worker_send_handshake(conn);

idle_count++;
Expand Down Expand Up @@ -232,7 +241,7 @@ static void auth_worker_destroy(struct auth_worker_connection **_conn,
idle_count--;

if (conn->request != NULL) {
i_error("auth worker: Aborted %s request for %s: %s",
e_error(conn->event, "Aborted %s request for %s: %s",
t_strcut(conn->request->data, '\t'),
conn->request->username, reason);
conn->request->callback(t_strdup_printf(
Expand All @@ -246,7 +255,8 @@ static void auth_worker_destroy(struct auth_worker_connection **_conn,
timeout_remove(&conn->to);

if (close(conn->fd) < 0)
i_error("close(auth worker) failed: %m");
e_error(conn->event, "close() failed: %m");
event_unref(&conn->event);
i_free(conn);

if (idle_count == 0 && restart) {
Expand Down Expand Up @@ -366,7 +376,8 @@ static void worker_input(struct auth_worker_connection *conn)
return;
case -2:
/* buffer full */
i_error("BUG: Auth worker sent us more than %d bytes",
e_error(conn->event,
"BUG: Auth worker sent us more than %d bytes",
(int)AUTH_WORKER_MAX_LINE_LENGTH);
auth_worker_destroy(&conn, "Worker is buggy", TRUE);
return;
Expand Down Expand Up @@ -402,10 +413,12 @@ static void worker_input(struct auth_worker_connection *conn)
break;
} else {
if (conn->request != NULL) {
i_error("BUG: Worker sent reply with id %u, "
e_error(conn->event,
"BUG: Worker sent reply with id %u, "
"expected %u", id, conn->request->id);
} else {
i_error("BUG: Worker sent reply with id %u, "
e_error(conn->event,
"BUG: Worker sent reply with id %u, "
"none was expected", id);
}
auth_worker_destroy(&conn, "Worker is buggy", TRUE);
Expand Down

0 comments on commit 19a40f3

Please sign in to comment.