Browse Source

[core] remove HANDLER_WAIT_FOR_FD

If a system call returns EMFILE, then admin should increase
server.max-fds and check/increase rlimits for num files (ulimit -Hn)

Alternatively, the admin might decrease server.max-connections to limit
the number of connections served in parallel.
master
Glenn Strauss 3 months ago
parent
commit
55d8ed1b25
  1. 1
      src/base.h
  2. 3
      src/base_decls.h
  3. 25
      src/connections.c
  4. 12
      src/gw_backend.c
  5. 2
      src/response.c
  6. 29
      src/server.c

1
src/base.h

@ -181,7 +181,6 @@ struct server {
uint32_t lim_conns;
connection *conns;
connection *conns_pool;
connections fdwaitqueue;
log_error_st *errh;

3
src/base_decls.h

@ -32,8 +32,7 @@ enum handler_t {
HANDLER_FINISHED,
HANDLER_COMEBACK,
HANDLER_WAIT_FOR_EVENT,
HANDLER_ERROR,
HANDLER_WAIT_FOR_FD
HANDLER_ERROR
};
typedef enum handler_t handler_t;

25
src/connections.c

@ -180,22 +180,6 @@ static void connection_handle_shutdown(connection *con) {
}
__attribute_cold__
static void connection_list_resize(connections *conns) {
conns->size += 16;
conns->ptr = realloc(conns->ptr, sizeof(*conns->ptr) * conns->size);
force_assert(NULL != conns->ptr);
}
__attribute_cold__
__attribute_noinline__
static void connection_fdwaitqueue_append(connection *con) {
connections * const conns = &con->srv->fdwaitqueue;
if (conns->used == conns->size) connection_list_resize(conns);
conns->ptr[conns->used++] = con;
}
static void connection_handle_response_end_state(request_st * const r, connection * const con) {
if (r->http_version > HTTP_VERSION_1_1) {
h2_retire_con(r, con);
@ -495,12 +479,6 @@ static int connection_handle_write_state(request_st * const r, connection * cons
case HANDLER_FINISHED:
case HANDLER_GO_ON:
break;
case HANDLER_WAIT_FOR_FD:
/* (In addition to waiting for dispatch from fdwaitqueue,
* HTTP/2 connections may retry more frequently after any
* activity occurs on connection or on other streams) */
connection_fdwaitqueue_append(con);
break;
case HANDLER_COMEBACK:
default:
log_error(r->conf.errh, __FILE__, __LINE__,
@ -1061,9 +1039,6 @@ connection_state_machine_loop (request_st * const r, connection * const con)
/* redo loop; will not match r->state */
ostate = CON_STATE_CONNECT;
continue;
case HANDLER_WAIT_FOR_FD:
connection_fdwaitqueue_append(con);
return;
/*case HANDLER_ERROR:*/
default:
connection_set_state_error(r, CON_STATE_ERROR);

12
src/gw_backend.c

@ -1910,15 +1910,9 @@ static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * cons
hctx->fd = fdevent_socket_nb_cloexec(hctx->host->family,SOCK_STREAM,0);
if (-1 == hctx->fd) {
log_error_st * const errh = r->conf.errh;
if (errno == EMFILE || errno == EINTR) {
log_error(errh, __FILE__, __LINE__,
"wait for fd at connection: %d", r->con->fd);
return HANDLER_WAIT_FOR_FD;
}
log_perror(errh, __FILE__, __LINE__,
"socket failed %d %d",r->con->srv->cur_fds,r->con->srv->max_fds);
log_perror(r->conf.errh, __FILE__, __LINE__,
"socket() failed (cur_fds:%d) (max_fds:%d)",
r->con->srv->cur_fds, r->con->srv->max_fds);
return HANDLER_ERROR;
}

2
src/response.c

@ -979,8 +979,6 @@ http_response_handler (request_st * const r)
/* we have something to send; go on */
/*(CON_STATE_RESPONSE_START; transient state)*/
return http_response_write_prepare(r);
case HANDLER_WAIT_FOR_FD:
return HANDLER_WAIT_FOR_FD;
case HANDLER_COMEBACK:
http_response_comeback(r);
return HANDLER_COMEBACK;

29
src/server.c

@ -331,8 +331,6 @@ static void server_free(server *srv) {
config_free(srv);
free(srv->fdwaitqueue.ptr);
stat_cache_free();
li_rand_cleanup();
@ -1037,9 +1035,6 @@ static void server_sockets_disable (server *srv) {
__attribute_cold__
static void server_overload_check (server *srv) {
if (srv->fdwaitqueue.used)
return;
if (srv->cur_fds < srv->max_fds_lowat && 0 != srv->lim_conns)
server_sockets_enable(srv);
}
@ -1050,26 +1045,6 @@ static void server_load_check (server *srv) {
server_sockets_disable(srv);
}
__attribute_cold__
__attribute_noinline__
static void server_process_fdwaitqueue (server *srv) {
connections * const fdwaitqueue = &srv->fdwaitqueue;
uint32_t i = 0;
for (int n = srv->max_fds - srv->cur_fds - 16; n > 0; --n) {
if (i == fdwaitqueue->used) break;
connection_state_machine(fdwaitqueue->ptr[i++]);
}
if (0 == (fdwaitqueue->used -= i)) {
free(fdwaitqueue->ptr);
fdwaitqueue->ptr = NULL;
fdwaitqueue->size = 0;
}
else if (i > 0) {
memmove(fdwaitqueue->ptr, fdwaitqueue->ptr+i,
fdwaitqueue->used * sizeof(*(fdwaitqueue->ptr)));
}
}
__attribute_cold__
static int server_main_setup (server * const srv, int argc, char **argv) {
int print_config = 0;
@ -1977,10 +1952,6 @@ static void server_main_loop (server * const srv) {
server_load_check(srv);
}
if (srv->fdwaitqueue.used) {
server_process_fdwaitqueue(srv);
}
static connection * const sentinel =
(connection *)(uintptr_t)&log_con_jqueue;
connection * const joblist = log_con_jqueue;

Loading…
Cancel
Save