[Solved] connection keep alive waits forever even when max-idle-time is configured
Added by Digambar almost 10 years ago
OS - Linux
Lightpd version - 1.4.32
I using curl to initiate a connection and Lighttpd is configured to enable connection keep-alive by default with HTTP1.1. When Curl sends Get; it gets answered. But then connection moves from RESPONE_END to REQSTART state in connection.c. In connection_state_machine; it loops to go to READ state and blocks on read call on socket.
In main server loop; there is code to timeout but it is never entered.
for (ndx = 0; ndx < conns->used; ndx++) {
is never true even though connection keep alive should set one connection used.
Is Lighttpd designed to wait forever if connection-keepalive is used ? or am i missing something here please
Replies (6)
RE: connection keep alive waits forever even when max-idle-time is configured - Added by stbuehler almost 10 years ago
[...] blocks on read call on socket.
And how would you know that? Or anything of the other stuff you claim?
RE: connection keep alive waits forever even when max-idle-time is configured - Added by Digambar almost 10 years ago
Hi Stefen,
I don't completely get your answer or question but let me try to explain again
In a configuration I have set
server.max-keep-alive-requests = 16
server.max-keep-alive-idle = 5
server.max-read-idle = 10
server.max-write-idle = 10
From client; I send HTTP 1.1 packet with enforced header - connection: keep-alive. When received on server; server is parsing correcting and connection's keepalive flag is updated.
As per code; and documentation
Keep-Alive (blue path)
The Keep-Alive handling is implemented by going from the 'respend'
directly to 'reqstart' without the close() and the accept() calls.
Straight from reqstart, it moves to READ state.
in connection_state_machine()
case CON_STATE_REQUEST_START: /* transient */
connection_set_state(srv, con, CON_STATE_READ);
and
case CON_STATE_READ:
connection_handle_read_state(srv, con);
which calls connection_handle_read and blocks on read.
I see there is mechanism in main to handle timeouts -
/**
* check all connections for timeouts
*
*/
for (ndx = 0; ndx < conns->used; ndx++) {
int changed = 0;
connection *con;
int t_diff;
con = conns->ptr[ndx];
if (con->state CON_STATE_READ ||
con->state CON_STATE_READ_POST) {
if (con->request_count == 1) {
if (srv->cur_ts - con->read_idle_ts > con->conf.max_read_idle) {
/* time - out */
But my trouble is whenever socket is waiting for data from client; it just waits forever. After CON_STATE_RESPONSE_END, conns->used is always ZERO.
Am I missing something ? We have this code for a while as version is older and I am wondering if there was any improvement or it is designed to work like this ?
Thanks
RE: connection keep alive waits forever even when max-idle-time is configured - Added by stbuehler almost 10 years ago
which calls connection_handle_read and blocks on read.
we don't block on read.
it just waits forever. After CON_STATE_RESPONSE_END, conns->used is always ZERO.
If it waits forever, how does it get to CON_STATE_RESPONSE_END? and yes, when the connection is really "ended", the connection gets removed.
If you want any help you should describe what you are doing, and what (and how) you are observing, and what you think is wrong with what you observed.
One good start is to attach strace to lighttpd, then run your client (curl, netcat, ...).
RE: connection keep alive waits forever even when max-idle-time is configured - Added by Digambar almost 10 years ago
I think I confused you.
On TCP connection; First GET request from client is accepted and replied properly. This results in CON_STATE_RESPONSE_END, and as keep alive flag is set on connection; state machine moves to REQStart and then READ state. It is this READ state where it is blocked till client sends any data.
If you see statemachine for keep-alive at
http://redmine.lighttpd.net/attachments/download/790/internal-http-states.png
Thanks
RE: connection keep alive waits forever even when max-idle-time is configured - Added by stbuehler almost 10 years ago
If you want any help you should describe what you are doing, and what (and how) you are observing, and what you think is wrong with what you observed.
I will ignore any further wild speculations about what you think is happening in lighttpd.
RE: connection keep alive waits forever even when max-idle-time is configured - Added by stbuehler almost 10 years ago
While preparing the 1.4.36~rc1 changelog I just noticed this commit: r2962 - maybe it contains a fix for whatever problems you are having.