2006-06-25 20:48:02 -04:00
/*
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* Stream management functions .
2006-06-25 20:48:02 -04:00
*
2012-04-19 13:28:33 -04:00
* Copyright 2000 - 2012 Willy Tarreau < w @ 1 wt . eu >
2006-06-25 20:48:02 -04:00
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version
* 2 of the License , or ( at your option ) any later version .
*
*/
# include <stdlib.h>
2010-06-01 11:45:26 -04:00
# include <unistd.h>
# include <fcntl.h>
2006-06-29 12:54:54 -04:00
2015-09-27 13:29:33 -04:00
# include <common/cfgparse.h>
2006-06-29 12:54:54 -04:00
# include <common/config.h>
2012-10-12 17:49:43 -04:00
# include <common/buffer.h>
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
# include <common/debug.h>
2006-06-29 11:53:05 -04:00
# include <common/memory.h>
2017-05-30 09:36:50 -04:00
# include <common/hathreads.h>
2006-06-25 20:48:02 -04:00
2015-04-13 07:24:54 -04:00
# include <types/applet.h>
2006-06-25 20:48:02 -04:00
# include <types/capture.h>
2016-11-21 02:51:11 -05:00
# include <types/cli.h>
MAJOR: filters: Add filters support
This patch adds the support of filters in HAProxy. The main idea is to have a
way to "easely" extend HAProxy by adding some "modules", called filters, that
will be able to change HAProxy behavior in a programmatic way.
To do so, many entry points has been added in code to let filters to hook up to
different steps of the processing. A filter must define a flt_ops sutrctures
(see include/types/filters.h for details). This structure contains all available
callbacks that a filter can define:
struct flt_ops {
/*
* Callbacks to manage the filter lifecycle
*/
int (*init) (struct proxy *p);
void (*deinit)(struct proxy *p);
int (*check) (struct proxy *p);
/*
* Stream callbacks
*/
void (*stream_start) (struct stream *s);
void (*stream_accept) (struct stream *s);
void (*session_establish)(struct stream *s);
void (*stream_stop) (struct stream *s);
/*
* HTTP callbacks
*/
int (*http_start) (struct stream *s, struct http_msg *msg);
int (*http_start_body) (struct stream *s, struct http_msg *msg);
int (*http_start_chunk) (struct stream *s, struct http_msg *msg);
int (*http_data) (struct stream *s, struct http_msg *msg);
int (*http_last_chunk) (struct stream *s, struct http_msg *msg);
int (*http_end_chunk) (struct stream *s, struct http_msg *msg);
int (*http_chunk_trailers)(struct stream *s, struct http_msg *msg);
int (*http_end_body) (struct stream *s, struct http_msg *msg);
void (*http_end) (struct stream *s, struct http_msg *msg);
void (*http_reset) (struct stream *s, struct http_msg *msg);
int (*http_pre_process) (struct stream *s, struct http_msg *msg);
int (*http_post_process) (struct stream *s, struct http_msg *msg);
void (*http_reply) (struct stream *s, short status,
const struct chunk *msg);
};
To declare and use a filter, in the configuration, the "filter" keyword must be
used in a listener/frontend section:
frontend test
...
filter <FILTER-NAME> [OPTIONS...]
The filter referenced by the <FILTER-NAME> must declare a configuration parser
on its own name to fill flt_ops and filter_conf field in the proxy's
structure. An exemple will be provided later to make it perfectly clear.
For now, filters cannot be used in backend section. But this is only a matter of
time. Documentation will also be added later. This is the first commit of a long
list about filters.
It is possible to have several filters on the same listener/frontend. These
filters are stored in an array of at most MAX_FILTERS elements (define in
include/types/filters.h). Again, this will be replaced later by a list of
filters.
The filter API has been highly refactored. Main changes are:
* Now, HA supports an infinite number of filters per proxy. To do so, filters
are stored in list.
* Because filters are stored in list, filters state has been moved from the
channel structure to the filter structure. This is cleaner because there is no
more info about filters in channel structure.
* It is possible to defined filters on backends only. For such filters,
stream_start/stream_stop callbacks are not called. Of course, it is possible
to mix frontend and backend filters.
* Now, TCP streams are also filtered. All callbacks without the 'http_' prefix
are called for all kind of streams. In addition, 2 new callbacks were added to
filter data exchanged through a TCP stream:
- tcp_data: it is called when new data are available or when old unprocessed
data are still waiting.
- tcp_forward_data: it is called when some data can be consumed.
* New callbacks attached to channel were added:
- channel_start_analyze: it is called when a filter is ready to process data
exchanged through a channel. 2 new analyzers (a frontend and a backend)
are attached to channels to call this callback. For a frontend filter, it
is called before any other analyzer. For a backend filter, it is called
when a backend is attached to a stream. So some processing cannot be
filtered in that case.
- channel_analyze: it is called before each analyzer attached to a channel,
expects analyzers responsible for data sending.
- channel_end_analyze: it is called when all other analyzers have finished
their processing. A new analyzers is attached to channels to call this
callback. For a TCP stream, this is always the last one called. For a HTTP
one, the callback is called when a request/response ends, so it is called
one time for each request/response.
* 'session_established' callback has been removed. Everything that is done in
this callback can be handled by 'channel_start_analyze' on the response
channel.
* 'http_pre_process' and 'http_post_process' callbacks have been replaced by
'channel_analyze'.
* 'http_start' callback has been replaced by 'http_headers'. This new one is
called just before headers sending and parsing of the body.
* 'http_end' callback has been replaced by 'channel_end_analyze'.
* It is possible to set a forwarder for TCP channels. It was already possible to
do it for HTTP ones.
* Forwarders can partially consumed forwardable data. For this reason a new
HTTP message state was added before HTTP_MSG_DONE : HTTP_MSG_ENDING.
Now all filters can define corresponding callbacks (http_forward_data
and tcp_forward_data). Each filter owns 2 offsets relative to buf->p, next and
forward, to track, respectively, input data already parsed but not forwarded yet
by the filter and parsed data considered as forwarded by the filter. A any time,
we have the warranty that a filter cannot parse or forward more input than
previous ones. And, of course, it cannot forward more input than it has
parsed. 2 macros has been added to retrieve these offets: FLT_NXT and FLT_FWD.
In addition, 2 functions has been added to change the 'next size' and the
'forward size' of a filter. When a filter parses input data, it can alter these
data, so the size of these data can vary. This action has an effet on all
previous filters that must be handled. To do so, the function
'filter_change_next_size' must be called, passing the size variation. In the
same spirit, if a filter alter forwarded data, it must call the function
'filter_change_forward_size'. 'filter_change_next_size' can be called in
'http_data' and 'tcp_data' callbacks and only these ones. And
'filter_change_forward_size' can be called in 'http_forward_data' and
'tcp_forward_data' callbacks and only these ones. The data changes are the
filter responsability, but with some limitation. It must not change already
parsed/forwarded data or data that previous filters have not parsed/forwarded
yet.
Because filters can be used on backends, when we the backend is set for a
stream, we add filters defined for this backend in the filter list of the
stream. But we must only do that when the backend and the frontend of the stream
are not the same. Else same filters are added a second time leading to undefined
behavior.
The HTTP compression code had to be moved.
So it simplifies http_response_forward_body function. To do so, the way the data
are forwarded has changed. Now, a filter (and only one) can forward data. In a
commit to come, this limitation will be removed to let all filters take part to
data forwarding. There are 2 new functions that filters should use to deal with
this feature:
* flt_set_http_data_forwarder: This function sets the filter (using its id)
that will forward data for the specified HTTP message. It is possible if it
was not already set by another filter _AND_ if no data was yet forwarded
(msg->msg_state <= HTTP_MSG_BODY). It returns -1 if an error occurs.
* flt_http_data_forwarder: This function returns the filter id that will
forward data for the specified HTTP message. If there is no forwarder set, it
returns -1.
When an HTTP data forwarder is set for the response, the HTTP compression is
disabled. Of course, this is not definitive.
2015-04-30 05:48:27 -04:00
# include <types/filters.h>
2008-11-30 12:47:21 -05:00
# include <types/global.h>
2016-11-21 11:49:11 -05:00
# include <types/stats.h>
2006-06-25 20:48:02 -04:00
2009-07-07 09:10:31 -04:00
# include <proto/acl.h>
2015-09-27 13:29:33 -04:00
# include <proto/action.h>
2012-04-19 12:42:05 -04:00
# include <proto/arg.h>
2008-11-30 12:47:21 -05:00
# include <proto/backend.h>
2012-08-24 13:22:53 -04:00
# include <proto/channel.h>
2009-12-15 16:31:24 -05:00
# include <proto/checks.h>
2016-11-21 02:51:11 -05:00
# include <proto/cli.h>
2012-07-06 08:29:45 -04:00
# include <proto/connection.h>
2016-11-21 11:49:11 -05:00
# include <proto/stats.h>
2012-09-02 16:34:23 -04:00
# include <proto/fd.h>
MAJOR: filters: Add filters support
This patch adds the support of filters in HAProxy. The main idea is to have a
way to "easely" extend HAProxy by adding some "modules", called filters, that
will be able to change HAProxy behavior in a programmatic way.
To do so, many entry points has been added in code to let filters to hook up to
different steps of the processing. A filter must define a flt_ops sutrctures
(see include/types/filters.h for details). This structure contains all available
callbacks that a filter can define:
struct flt_ops {
/*
* Callbacks to manage the filter lifecycle
*/
int (*init) (struct proxy *p);
void (*deinit)(struct proxy *p);
int (*check) (struct proxy *p);
/*
* Stream callbacks
*/
void (*stream_start) (struct stream *s);
void (*stream_accept) (struct stream *s);
void (*session_establish)(struct stream *s);
void (*stream_stop) (struct stream *s);
/*
* HTTP callbacks
*/
int (*http_start) (struct stream *s, struct http_msg *msg);
int (*http_start_body) (struct stream *s, struct http_msg *msg);
int (*http_start_chunk) (struct stream *s, struct http_msg *msg);
int (*http_data) (struct stream *s, struct http_msg *msg);
int (*http_last_chunk) (struct stream *s, struct http_msg *msg);
int (*http_end_chunk) (struct stream *s, struct http_msg *msg);
int (*http_chunk_trailers)(struct stream *s, struct http_msg *msg);
int (*http_end_body) (struct stream *s, struct http_msg *msg);
void (*http_end) (struct stream *s, struct http_msg *msg);
void (*http_reset) (struct stream *s, struct http_msg *msg);
int (*http_pre_process) (struct stream *s, struct http_msg *msg);
int (*http_post_process) (struct stream *s, struct http_msg *msg);
void (*http_reply) (struct stream *s, short status,
const struct chunk *msg);
};
To declare and use a filter, in the configuration, the "filter" keyword must be
used in a listener/frontend section:
frontend test
...
filter <FILTER-NAME> [OPTIONS...]
The filter referenced by the <FILTER-NAME> must declare a configuration parser
on its own name to fill flt_ops and filter_conf field in the proxy's
structure. An exemple will be provided later to make it perfectly clear.
For now, filters cannot be used in backend section. But this is only a matter of
time. Documentation will also be added later. This is the first commit of a long
list about filters.
It is possible to have several filters on the same listener/frontend. These
filters are stored in an array of at most MAX_FILTERS elements (define in
include/types/filters.h). Again, this will be replaced later by a list of
filters.
The filter API has been highly refactored. Main changes are:
* Now, HA supports an infinite number of filters per proxy. To do so, filters
are stored in list.
* Because filters are stored in list, filters state has been moved from the
channel structure to the filter structure. This is cleaner because there is no
more info about filters in channel structure.
* It is possible to defined filters on backends only. For such filters,
stream_start/stream_stop callbacks are not called. Of course, it is possible
to mix frontend and backend filters.
* Now, TCP streams are also filtered. All callbacks without the 'http_' prefix
are called for all kind of streams. In addition, 2 new callbacks were added to
filter data exchanged through a TCP stream:
- tcp_data: it is called when new data are available or when old unprocessed
data are still waiting.
- tcp_forward_data: it is called when some data can be consumed.
* New callbacks attached to channel were added:
- channel_start_analyze: it is called when a filter is ready to process data
exchanged through a channel. 2 new analyzers (a frontend and a backend)
are attached to channels to call this callback. For a frontend filter, it
is called before any other analyzer. For a backend filter, it is called
when a backend is attached to a stream. So some processing cannot be
filtered in that case.
- channel_analyze: it is called before each analyzer attached to a channel,
expects analyzers responsible for data sending.
- channel_end_analyze: it is called when all other analyzers have finished
their processing. A new analyzers is attached to channels to call this
callback. For a TCP stream, this is always the last one called. For a HTTP
one, the callback is called when a request/response ends, so it is called
one time for each request/response.
* 'session_established' callback has been removed. Everything that is done in
this callback can be handled by 'channel_start_analyze' on the response
channel.
* 'http_pre_process' and 'http_post_process' callbacks have been replaced by
'channel_analyze'.
* 'http_start' callback has been replaced by 'http_headers'. This new one is
called just before headers sending and parsing of the body.
* 'http_end' callback has been replaced by 'channel_end_analyze'.
* It is possible to set a forwarder for TCP channels. It was already possible to
do it for HTTP ones.
* Forwarders can partially consumed forwardable data. For this reason a new
HTTP message state was added before HTTP_MSG_DONE : HTTP_MSG_ENDING.
Now all filters can define corresponding callbacks (http_forward_data
and tcp_forward_data). Each filter owns 2 offsets relative to buf->p, next and
forward, to track, respectively, input data already parsed but not forwarded yet
by the filter and parsed data considered as forwarded by the filter. A any time,
we have the warranty that a filter cannot parse or forward more input than
previous ones. And, of course, it cannot forward more input than it has
parsed. 2 macros has been added to retrieve these offets: FLT_NXT and FLT_FWD.
In addition, 2 functions has been added to change the 'next size' and the
'forward size' of a filter. When a filter parses input data, it can alter these
data, so the size of these data can vary. This action has an effet on all
previous filters that must be handled. To do so, the function
'filter_change_next_size' must be called, passing the size variation. In the
same spirit, if a filter alter forwarded data, it must call the function
'filter_change_forward_size'. 'filter_change_next_size' can be called in
'http_data' and 'tcp_data' callbacks and only these ones. And
'filter_change_forward_size' can be called in 'http_forward_data' and
'tcp_forward_data' callbacks and only these ones. The data changes are the
filter responsability, but with some limitation. It must not change already
parsed/forwarded data or data that previous filters have not parsed/forwarded
yet.
Because filters can be used on backends, when we the backend is set for a
stream, we add filters defined for this backend in the filter list of the
stream. But we must only do that when the backend and the frontend of the stream
are not the same. Else same filters are added a second time leading to undefined
behavior.
The HTTP compression code had to be moved.
So it simplifies http_response_forward_body function. To do so, the way the data
are forwarded has changed. Now, a filter (and only one) can forward data. In a
commit to come, this limitation will be removed to let all filters take part to
data forwarding. There are 2 new functions that filters should use to deal with
this feature:
* flt_set_http_data_forwarder: This function sets the filter (using its id)
that will forward data for the specified HTTP message. It is possible if it
was not already set by another filter _AND_ if no data was yet forwarded
(msg->msg_state <= HTTP_MSG_BODY). It returns -1 if an error occurs.
* flt_http_data_forwarder: This function returns the filter id that will
forward data for the specified HTTP message. If there is no forwarder set, it
returns -1.
When an HTTP data forwarder is set for the response, the HTTP compression is
disabled. Of course, this is not definitive.
2015-04-30 05:48:27 -04:00
# include <proto/filters.h>
2010-06-20 05:19:22 -04:00
# include <proto/freq_ctr.h>
2010-10-15 17:25:20 -04:00
# include <proto/frontend.h>
2007-01-21 13:16:41 -05:00
# include <proto/hdr_idx.h>
2015-02-16 14:11:43 -05:00
# include <proto/hlua.h>
2012-09-12 16:58:11 -04:00
# include <proto/listener.h>
2007-05-13 15:36:56 -04:00
# include <proto/log.h>
2012-09-06 05:32:07 -04:00
# include <proto/raw_sock.h>
2015-04-03 08:10:06 -04:00
# include <proto/session.h>
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
# include <proto/stream.h>
2009-01-25 07:56:13 -05:00
# include <proto/pipe.h>
2008-11-30 12:47:21 -05:00
# include <proto/proto_http.h>
2009-07-07 09:10:31 -04:00
# include <proto/proxy.h>
2006-06-25 20:48:02 -04:00
# include <proto/queue.h>
2009-03-05 12:43:00 -05:00
# include <proto/server.h>
2012-04-27 15:52:18 -04:00
# include <proto/sample.h>
2010-01-04 09:47:17 -05:00
# include <proto/stick_table.h>
2008-11-30 12:47:21 -05:00
# include <proto/stream_interface.h>
# include <proto/task.h>
2016-11-25 09:49:32 -05:00
# include <proto/tcp_rules.h>
2015-06-06 13:29:07 -04:00
# include <proto/vars.h>
2006-06-25 20:48:02 -04:00
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
struct pool_head * pool2_stream ;
struct list streams ;
2017-11-13 04:34:01 -05:00
__decl_hathreads ( HA_SPINLOCK_T streams_lock ) ;
2006-06-25 20:48:02 -04:00
2015-09-27 13:29:33 -04:00
/* List of all use-service keywords. */
static struct list service_keywords = LIST_HEAD_INIT ( service_keywords ) ;
2017-08-28 11:18:36 -04:00
/* Create a new stream for connection <conn>. Return < 0 on error. This is only
* valid right after the handshake , before the connection ' s data layer is
* initialized , because it relies on the session to be in conn - > owner .
*/
2017-09-13 12:30:23 -04:00
int stream_create_from_cs ( struct conn_stream * cs )
2017-08-28 11:18:36 -04:00
{
struct stream * strm ;
2017-09-13 12:30:23 -04:00
strm = stream_new ( cs - > conn - > owner , & cs - > obj_type ) ;
2017-08-28 11:18:36 -04:00
if ( strm = = NULL )
return - 1 ;
task_wakeup ( strm - > task , TASK_WOKEN_INIT ) ;
return 0 ;
}
2015-04-04 12:50:31 -04:00
/* This function is called from the session handler which detects the end of
2015-04-08 12:26:29 -04:00
* handshake , in order to complete initialization of a valid stream . It must be
2017-08-28 10:22:54 -04:00
* called with a completley initialized session . It returns the pointer to
2015-04-08 12:26:29 -04:00
* the newly created stream , or NULL in case of fatal error . The client - facing
2017-08-28 10:22:54 -04:00
* end point is assigned to < origin > , which must be valid . The stream ' s task
* is configured with a nice value inherited from the listener ' s nice if any .
* The task ' s context is set to the new stream , and its function is set to
* process_stream ( ) . Target and analysers are null .
2012-08-31 10:01:23 -04:00
*/
2017-08-28 10:22:54 -04:00
struct stream * stream_new ( struct session * sess , enum obj_type * origin )
2012-08-31 10:01:23 -04:00
{
2015-04-04 12:08:21 -04:00
struct stream * s ;
2017-08-28 10:22:54 -04:00
struct task * t ;
2017-09-13 12:30:23 -04:00
struct conn_stream * cs = objt_cs ( origin ) ;
2015-04-08 12:26:29 -04:00
struct appctx * appctx = objt_appctx ( origin ) ;
2012-08-31 10:01:23 -04:00
2015-04-04 12:08:21 -04:00
if ( unlikely ( ( s = pool_alloc2 ( pool2_stream ) ) = = NULL ) )
2017-08-28 10:22:54 -04:00
goto out_fail_alloc ;
2015-04-04 12:08:21 -04:00
/* minimum stream initialization required for an embryonic stream is
* fairly low . We need very little to execute L4 ACLs , then we need a
* task to make the client - side connection live on its own .
* - flags
* - stick - entry tracking
*/
s - > flags = 0 ;
2015-04-05 12:19:23 -04:00
s - > logs . logwait = sess - > fe - > to_log ;
2015-04-04 12:08:21 -04:00
s - > logs . level = 0 ;
2015-04-05 06:03:54 -04:00
s - > logs . accept_date = sess - > accept_date ; /* user-visible date for logging */
s - > logs . tv_accept = sess - > tv_accept ; /* corrected date for internal use */
MEDIUM: log: Decompose %Tq in %Th %Ti %TR
Tq is the time between the instant the connection is accepted and a
complete valid request is received. This time includes the handshake
(SSL / Proxy-Protocol), the idle when the browser does preconnect and
the request reception.
This patch decomposes %Tq in 3 measurements names %Th, %Ti, and %TR
which returns respectively the handshake time, the idle time and the
duration of valid request reception. It also adds %Ta which reports
the request's active time, which is the total time without %Th nor %Ti.
It replaces %Tt as the total time, reporting accurate measurements for
HTTP persistent connections.
%Th is avalaible for TCP and HTTP sessions, %Ti, %TR and %Ta are only
avalaible for HTTP connections.
In addition to this, we have new timestamps %tr, %trg and %trl, which
log the date of start of receipt of the request, respectively in the
default format, in GMT time and in local time (by analogy with %t, %T
and %Tl). All of them are obviously only available for HTTP. These values
are more relevant as they more accurately represent the request date
without being skewed by a browser's preconnect nor a keep-alive idle
time.
The HTTP log format and the CLF log format have been modified to
use %tr, %TR, and %Ta respectively instead of %t, %Tq and %Tt. This
way the default log formats now produce the expected output for users
who don't want to manually fiddle with the log-format directive.
Example with the following log-format :
log-format "%ci:%cp [%tr] %ft %b/%s h=%Th/i=%Ti/R=%TR/w=%Tw/c=%Tc/r=%Tr/a=%Ta/t=%Tt %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
The request was sent by hand using "openssl s_client -connect" :
Aug 23 14:43:20 haproxy[25446]: 127.0.0.1:45636 [23/Aug/2016:14:43:20.221] test~ test/test h=6/i=2375/R=261/w=0/c=1/r=0/a=262/t=2643 200 145 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"
=> 6 ms of SSL handshake, 2375 waiting before sending the first char (in
fact the time to type the first line), 261 ms before the end of the request,
no time spent in queue, 1 ms spend connecting to the server, immediate
response, total active time for this request = 262ms. Total time from accept
to close : 2643 ms.
The timing now decomposes like this :
first request 2nd request
|<-------------------------------->|<-------------- ...
t tr t tr ...
---|----|----|----|----|----|----|----|----|--
: Th Ti TR Tw Tc Tr Td : Ti ...
:<---- Tq ---->: :
:<-------------- Tt -------------->:
:<--------- Ta --------->:
2016-07-28 11:19:45 -04:00
/* This function is called just after the handshake, so the handshake duration is
* between the accept time and now .
*/
s - > logs . t_handshake = tv_ms_elapsed ( & sess - > tv_accept , & now ) ;
s - > logs . t_idle = - 1 ;
2015-04-05 06:03:54 -04:00
tv_zero ( & s - > logs . tv_request ) ;
s - > logs . t_queue = - 1 ;
s - > logs . t_connect = - 1 ;
s - > logs . t_data = - 1 ;
s - > logs . t_close = 0 ;
s - > logs . bytes_in = s - > logs . bytes_out = 0 ;
s - > logs . prx_queue_size = 0 ; /* we get the number of pending conns before us */
s - > logs . srv_queue_size = 0 ; /* we will get this number soon */
/* default logging function */
s - > do_log = strm_log ;
/* default error reporting function, may be changed by analysers */
s - > srv_error = default_srv_error ;
2015-04-04 12:08:21 -04:00
/* Initialise the current rule list pointer to NULL. We are sure that
* any rulelist match the NULL pointer .
*/
s - > current_rule_list = NULL ;
2015-07-22 11:10:58 -04:00
s - > current_rule = NULL ;
2015-04-04 12:08:21 -04:00
2015-09-21 11:48:24 -04:00
/* Copy SC counters for the stream. We don't touch refcounts because
* any reference we have is inherited from the session . Since the stream
* doesn ' t exist without the session , the session ' s existence guarantees
* we don ' t lose the entry . During the store operation , the stream won ' t
* touch these ones .
2015-08-18 05:34:18 -04:00
*/
2015-08-16 06:03:39 -04:00
memcpy ( s - > stkctr , sess - > stkctr , sizeof ( s - > stkctr ) ) ;
2015-04-04 12:08:21 -04:00
s - > sess = sess ;
s - > si [ 0 ] . flags = SI_FL_NONE ;
s - > si [ 1 ] . flags = SI_FL_ISBACK ;
s - > uniq_id = global . req_count + + ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* OK, we're keeping the stream, so let's properly initialize the stream */
2012-08-31 10:01:23 -04:00
LIST_INIT ( & s - > back_refs ) ;
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
LIST_INIT ( & s - > buffer_wait . list ) ;
s - > buffer_wait . target = s ;
s - > buffer_wait . wakeup_cb = ( int ( * ) ( void * ) ) stream_res_wakeup ;
2013-10-14 15:32:07 -04:00
2015-04-02 19:14:29 -04:00
s - > flags | = SF_INITIALIZED ;
2012-08-31 10:01:23 -04:00
s - > unique_id = NULL ;
2017-09-27 08:59:38 -04:00
if ( ( t = task_new ( tid_bit ) ) = = NULL )
2017-08-28 10:22:54 -04:00
goto out_fail_alloc ;
2015-04-04 12:08:21 -04:00
s - > task = t ;
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
s - > pending_events = 0 ;
2015-04-05 18:25:48 -04:00
t - > process = process_stream ;
2012-08-31 10:01:23 -04:00
t - > context = s ;
t - > expire = TICK_ETERNITY ;
2017-08-28 10:22:54 -04:00
if ( sess - > listener )
t - > nice = sess - > listener - > nice ;
2012-08-31 10:01:23 -04:00
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* Note: initially, the stream's backend points to the frontend.
2012-08-31 10:01:23 -04:00
* This changes later when switching rules are executed or
* when the default backend is assigned .
*/
2015-04-03 09:40:56 -04:00
s - > be = sess - > fe ;
2014-11-27 14:45:39 -05:00
s - > req . buf = s - > res . buf = NULL ;
2015-04-03 16:16:32 -04:00
s - > req_cap = NULL ;
s - > res_cap = NULL ;
2010-11-11 04:56:04 -05:00
2015-06-19 05:59:02 -04:00
/* Initialise all the variables contexts even if not used.
* This permits to prune these contexts without errors .
2015-06-06 13:29:07 -04:00
*/
vars_init ( & s - > vars_txn , SCOPE_TXN ) ;
vars_init ( & s - > vars_reqres , SCOPE_REQ ) ;
2013-10-11 13:34:20 -04:00
/* this part should be common with other protocols */
2014-11-28 06:12:34 -05:00
si_reset ( & s - > si [ 0 ] ) ;
2013-10-11 13:34:20 -04:00
si_set_state ( & s - > si [ 0 ] , SI_ST_EST ) ;
BUG/MEDIUM: stream: fix client-fin/server-fin handling
A tcp half connection can cause 100% CPU on expiration.
First reproduced with this haproxy configuration :
global
tune.bufsize 10485760
defaults
timeout server-fin 90s
timeout client-fin 90s
backend node2
mode tcp
timeout server 900s
timeout connect 10s
server def 127.0.0.1:3333
frontend fe_api
mode tcp
timeout client 900s
bind :1990
use_backend node2
Ie timeout server-fin shorter than timeout server, the backend server
sends data, this package is left in the cache of haproxy, the backend
server continue sending fin package, haproxy recv fin package. this
time the session information is as follows:
time the session information is as follows:
0x2373470: proto=tcpv4 src=127.0.0.1:39513 fe=fe_api be=node2
srv=def ts=08 age=1s calls=3 rq[f=848000h,i=0,an=00h,rx=14m58s,wx=,ax=]
rp[f=8004c020h,i=0,an=00h,rx=,wx=14m58s,ax=] s0=[7,0h,fd=6,ex=]
s1=[7,18h,fd=7,ex=] exp=14m58s
rp has set the CF_SHUTR state, next, the client sends the fin package,
session information is as follows:
0x2373470: proto=tcpv4 src=127.0.0.1:39513 fe=fe_api be=node2
srv=def ts=08 age=38s calls=4 rq[f=84a020h,i=0,an=00h,rx=,wx=,ax=]
rp[f=8004c020h,i=0,an=00h,rx=1m11s,wx=14m21s,ax=] s0=[7,0h,fd=6,ex=]
s1=[9,10h,fd=7,ex=] exp=1m11s
After waiting 90s, session information is as follows:
0x2373470: proto=tcpv4 src=127.0.0.1:39513 fe=fe_api be=node2
srv=def ts=04 age=4m11s calls=718074391 rq[f=84a020h,i=0,an=00h,rx=,wx=,ax=]
rp[f=8004c020h,i=0,an=00h,rx=?,wx=10m49s,ax=] s0=[7,0h,fd=6,ex=]
s1=[9,10h,fd=7,ex=] exp=? run(nice=0)
cpu information:
6899 root 20 0 112224 21408 4260 R 100.0 0.7 3:04.96 haproxy
Buffering is set to ensure that there is data in the haproxy buffer, and haproxy
can receive the fin package, set the CF_SHUTR flag, If the CF_SHUTR flag has been
set, The following code does not clear the timeout message, causing cpu 100%:
stream.c:process_stream:
if (unlikely((res->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
if (si_b->flags & SI_FL_NOHALF)
si_b->flags |= SI_FL_NOLINGER;
si_shutr(si_b);
}
If you have closed the read, set the read timeout does not make sense.
With or without cf_shutr, read timeout is set:
if (tick_isset(s->be->timeout.serverfin)) {
res->rto = s->be->timeout.serverfin;
res->rex = tick_add(now_ms, res->rto);
}
After discussion on the mailing list, setting half-closed timeouts the
hard way here doesn't make sense. They should be set only at the moment
the shutdown() is performed. It will also solve a special case which was
already reported of some half-closed timeouts not working when the shutw()
is performed directly at the stream-interface layer (no analyser involved).
Since the stream interface layer cannot know the timeout values, we'll have
to store them directly in the stream interface so that they are used upon
shutw(). This patch does this, fixing the problem.
An easier reproducer to validate the fix is to keep the huge buffer and
shorten all timeouts, then call it under tcploop server and client, and
wait 3 seconds to see haproxy run at 100% CPU :
global
tune.bufsize 10485760
listen px
bind :1990
timeout client 90s
timeout server 90s
timeout connect 1s
timeout server-fin 3s
timeout client-fin 3s
server def 127.0.0.1:3333
$ tcploop 3333 L W N20 A P100 F P10000 &
$ tcploop 127.0.0.1:1990 C S10000000 F
2017-03-10 12:41:51 -05:00
s - > si [ 0 ] . hcto = sess - > fe - > timeout . clientfin ;
2013-10-11 13:34:20 -04:00
2015-04-04 08:28:46 -04:00
/* attach the incoming connection to the stream interface now. */
2017-09-13 12:30:23 -04:00
if ( cs )
si_attach_cs ( & s - > si [ 0 ] , cs ) ;
2015-04-04 19:33:13 -04:00
else if ( appctx )
si_attach_appctx ( & s - > si [ 0 ] , appctx ) ;
2013-10-11 13:34:20 -04:00
2015-04-03 09:40:56 -04:00
if ( likely ( sess - > fe - > options2 & PR_O2_INDEPSTR ) )
2013-10-11 13:34:20 -04:00
s - > si [ 0 ] . flags | = SI_FL_INDEP_STR ;
2010-06-01 11:45:26 -04:00
/* pre-initialize the other side's stream interface to an INIT state. The
* callbacks will be initialized before attempting to connect .
*/
2014-11-28 06:12:34 -05:00
si_reset ( & s - > si [ 1 ] ) ;
BUG/MEDIUM: stream: fix client-fin/server-fin handling
A tcp half connection can cause 100% CPU on expiration.
First reproduced with this haproxy configuration :
global
tune.bufsize 10485760
defaults
timeout server-fin 90s
timeout client-fin 90s
backend node2
mode tcp
timeout server 900s
timeout connect 10s
server def 127.0.0.1:3333
frontend fe_api
mode tcp
timeout client 900s
bind :1990
use_backend node2
Ie timeout server-fin shorter than timeout server, the backend server
sends data, this package is left in the cache of haproxy, the backend
server continue sending fin package, haproxy recv fin package. this
time the session information is as follows:
time the session information is as follows:
0x2373470: proto=tcpv4 src=127.0.0.1:39513 fe=fe_api be=node2
srv=def ts=08 age=1s calls=3 rq[f=848000h,i=0,an=00h,rx=14m58s,wx=,ax=]
rp[f=8004c020h,i=0,an=00h,rx=,wx=14m58s,ax=] s0=[7,0h,fd=6,ex=]
s1=[7,18h,fd=7,ex=] exp=14m58s
rp has set the CF_SHUTR state, next, the client sends the fin package,
session information is as follows:
0x2373470: proto=tcpv4 src=127.0.0.1:39513 fe=fe_api be=node2
srv=def ts=08 age=38s calls=4 rq[f=84a020h,i=0,an=00h,rx=,wx=,ax=]
rp[f=8004c020h,i=0,an=00h,rx=1m11s,wx=14m21s,ax=] s0=[7,0h,fd=6,ex=]
s1=[9,10h,fd=7,ex=] exp=1m11s
After waiting 90s, session information is as follows:
0x2373470: proto=tcpv4 src=127.0.0.1:39513 fe=fe_api be=node2
srv=def ts=04 age=4m11s calls=718074391 rq[f=84a020h,i=0,an=00h,rx=,wx=,ax=]
rp[f=8004c020h,i=0,an=00h,rx=?,wx=10m49s,ax=] s0=[7,0h,fd=6,ex=]
s1=[9,10h,fd=7,ex=] exp=? run(nice=0)
cpu information:
6899 root 20 0 112224 21408 4260 R 100.0 0.7 3:04.96 haproxy
Buffering is set to ensure that there is data in the haproxy buffer, and haproxy
can receive the fin package, set the CF_SHUTR flag, If the CF_SHUTR flag has been
set, The following code does not clear the timeout message, causing cpu 100%:
stream.c:process_stream:
if (unlikely((res->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) {
if (si_b->flags & SI_FL_NOHALF)
si_b->flags |= SI_FL_NOLINGER;
si_shutr(si_b);
}
If you have closed the read, set the read timeout does not make sense.
With or without cf_shutr, read timeout is set:
if (tick_isset(s->be->timeout.serverfin)) {
res->rto = s->be->timeout.serverfin;
res->rex = tick_add(now_ms, res->rto);
}
After discussion on the mailing list, setting half-closed timeouts the
hard way here doesn't make sense. They should be set only at the moment
the shutdown() is performed. It will also solve a special case which was
already reported of some half-closed timeouts not working when the shutw()
is performed directly at the stream-interface layer (no analyser involved).
Since the stream interface layer cannot know the timeout values, we'll have
to store them directly in the stream interface so that they are used upon
shutw(). This patch does this, fixing the problem.
An easier reproducer to validate the fix is to keep the huge buffer and
shorten all timeouts, then call it under tcploop server and client, and
wait 3 seconds to see haproxy run at 100% CPU :
global
tune.bufsize 10485760
listen px
bind :1990
timeout client 90s
timeout server 90s
timeout connect 1s
timeout server-fin 3s
timeout client-fin 3s
server def 127.0.0.1:3333
$ tcploop 3333 L W N20 A P100 F P10000 &
$ tcploop 127.0.0.1:1990 C S10000000 F
2017-03-10 12:41:51 -05:00
s - > si [ 1 ] . hcto = TICK_ETERNITY ;
2013-10-01 04:45:07 -04:00
2015-04-03 09:40:56 -04:00
if ( likely ( sess - > fe - > options2 & PR_O2_INDEPSTR ) )
2010-06-01 11:45:26 -04:00
s - > si [ 1 ] . flags | = SI_FL_INDEP_STR ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_init_srv_conn ( s ) ;
2016-12-04 18:26:31 -05:00
s - > target = sess - > listener ? sess - > listener - > default_target : NULL ;
2010-06-01 11:45:26 -04:00
s - > pend_pos = NULL ;
/* init store persistence */
s - > store_count = 0 ;
2014-11-27 14:45:39 -05:00
channel_init ( & s - > req ) ;
s - > req . flags | = CF_READ_ATTACHED ; /* the producer is already connected */
2016-12-04 18:26:31 -05:00
s - > req . analysers = sess - > listener ? sess - > listener - > analysers : 0 ;
2015-04-05 18:25:48 -04:00
channel_auto_connect ( & s - > req ) ; /* don't wait to establish connection */
channel_auto_close ( & s - > req ) ; /* let the producer forward close requests */
2015-04-05 12:15:59 -04:00
s - > req . rto = sess - > fe - > timeout . client ;
2014-11-27 14:45:39 -05:00
s - > req . wto = TICK_ETERNITY ;
s - > req . rex = TICK_ETERNITY ;
s - > req . wex = TICK_ETERNITY ;
s - > req . analyse_exp = TICK_ETERNITY ;
2014-11-24 05:36:57 -05:00
2014-11-27 14:45:39 -05:00
channel_init ( & s - > res ) ;
2014-11-28 08:17:09 -05:00
s - > res . flags | = CF_ISRESP ;
2014-11-27 14:45:39 -05:00
s - > res . analysers = 0 ;
2010-06-01 11:45:26 -04:00
2015-04-03 09:40:56 -04:00
if ( sess - > fe - > options2 & PR_O2_NODELAY ) {
2014-11-27 14:45:39 -05:00
s - > req . flags | = CF_NEVER_WAIT ;
s - > res . flags | = CF_NEVER_WAIT ;
2011-05-30 12:10:30 -04:00
}
2015-04-05 12:15:59 -04:00
s - > res . wto = sess - > fe - > timeout . client ;
2014-11-27 14:45:39 -05:00
s - > res . rto = TICK_ETERNITY ;
s - > res . rex = TICK_ETERNITY ;
s - > res . wex = TICK_ETERNITY ;
s - > res . analyse_exp = TICK_ETERNITY ;
2010-06-01 11:45:26 -04:00
2015-04-03 17:46:31 -04:00
s - > txn = NULL ;
2016-12-17 06:45:32 -05:00
s - > hlua = NULL ;
2015-02-16 14:11:43 -05:00
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( STRMS_LOCK , & streams_lock ) ;
2017-06-30 10:23:45 -04:00
LIST_ADDQ ( & streams , & s - > list ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2017-06-30 10:23:45 -04:00
2015-11-05 07:35:03 -05:00
if ( flt_stream_init ( s ) < 0 | | flt_stream_start ( s ) < 0 )
MAJOR: filters: Add filters support
This patch adds the support of filters in HAProxy. The main idea is to have a
way to "easely" extend HAProxy by adding some "modules", called filters, that
will be able to change HAProxy behavior in a programmatic way.
To do so, many entry points has been added in code to let filters to hook up to
different steps of the processing. A filter must define a flt_ops sutrctures
(see include/types/filters.h for details). This structure contains all available
callbacks that a filter can define:
struct flt_ops {
/*
* Callbacks to manage the filter lifecycle
*/
int (*init) (struct proxy *p);
void (*deinit)(struct proxy *p);
int (*check) (struct proxy *p);
/*
* Stream callbacks
*/
void (*stream_start) (struct stream *s);
void (*stream_accept) (struct stream *s);
void (*session_establish)(struct stream *s);
void (*stream_stop) (struct stream *s);
/*
* HTTP callbacks
*/
int (*http_start) (struct stream *s, struct http_msg *msg);
int (*http_start_body) (struct stream *s, struct http_msg *msg);
int (*http_start_chunk) (struct stream *s, struct http_msg *msg);
int (*http_data) (struct stream *s, struct http_msg *msg);
int (*http_last_chunk) (struct stream *s, struct http_msg *msg);
int (*http_end_chunk) (struct stream *s, struct http_msg *msg);
int (*http_chunk_trailers)(struct stream *s, struct http_msg *msg);
int (*http_end_body) (struct stream *s, struct http_msg *msg);
void (*http_end) (struct stream *s, struct http_msg *msg);
void (*http_reset) (struct stream *s, struct http_msg *msg);
int (*http_pre_process) (struct stream *s, struct http_msg *msg);
int (*http_post_process) (struct stream *s, struct http_msg *msg);
void (*http_reply) (struct stream *s, short status,
const struct chunk *msg);
};
To declare and use a filter, in the configuration, the "filter" keyword must be
used in a listener/frontend section:
frontend test
...
filter <FILTER-NAME> [OPTIONS...]
The filter referenced by the <FILTER-NAME> must declare a configuration parser
on its own name to fill flt_ops and filter_conf field in the proxy's
structure. An exemple will be provided later to make it perfectly clear.
For now, filters cannot be used in backend section. But this is only a matter of
time. Documentation will also be added later. This is the first commit of a long
list about filters.
It is possible to have several filters on the same listener/frontend. These
filters are stored in an array of at most MAX_FILTERS elements (define in
include/types/filters.h). Again, this will be replaced later by a list of
filters.
The filter API has been highly refactored. Main changes are:
* Now, HA supports an infinite number of filters per proxy. To do so, filters
are stored in list.
* Because filters are stored in list, filters state has been moved from the
channel structure to the filter structure. This is cleaner because there is no
more info about filters in channel structure.
* It is possible to defined filters on backends only. For such filters,
stream_start/stream_stop callbacks are not called. Of course, it is possible
to mix frontend and backend filters.
* Now, TCP streams are also filtered. All callbacks without the 'http_' prefix
are called for all kind of streams. In addition, 2 new callbacks were added to
filter data exchanged through a TCP stream:
- tcp_data: it is called when new data are available or when old unprocessed
data are still waiting.
- tcp_forward_data: it is called when some data can be consumed.
* New callbacks attached to channel were added:
- channel_start_analyze: it is called when a filter is ready to process data
exchanged through a channel. 2 new analyzers (a frontend and a backend)
are attached to channels to call this callback. For a frontend filter, it
is called before any other analyzer. For a backend filter, it is called
when a backend is attached to a stream. So some processing cannot be
filtered in that case.
- channel_analyze: it is called before each analyzer attached to a channel,
expects analyzers responsible for data sending.
- channel_end_analyze: it is called when all other analyzers have finished
their processing. A new analyzers is attached to channels to call this
callback. For a TCP stream, this is always the last one called. For a HTTP
one, the callback is called when a request/response ends, so it is called
one time for each request/response.
* 'session_established' callback has been removed. Everything that is done in
this callback can be handled by 'channel_start_analyze' on the response
channel.
* 'http_pre_process' and 'http_post_process' callbacks have been replaced by
'channel_analyze'.
* 'http_start' callback has been replaced by 'http_headers'. This new one is
called just before headers sending and parsing of the body.
* 'http_end' callback has been replaced by 'channel_end_analyze'.
* It is possible to set a forwarder for TCP channels. It was already possible to
do it for HTTP ones.
* Forwarders can partially consumed forwardable data. For this reason a new
HTTP message state was added before HTTP_MSG_DONE : HTTP_MSG_ENDING.
Now all filters can define corresponding callbacks (http_forward_data
and tcp_forward_data). Each filter owns 2 offsets relative to buf->p, next and
forward, to track, respectively, input data already parsed but not forwarded yet
by the filter and parsed data considered as forwarded by the filter. A any time,
we have the warranty that a filter cannot parse or forward more input than
previous ones. And, of course, it cannot forward more input than it has
parsed. 2 macros has been added to retrieve these offets: FLT_NXT and FLT_FWD.
In addition, 2 functions has been added to change the 'next size' and the
'forward size' of a filter. When a filter parses input data, it can alter these
data, so the size of these data can vary. This action has an effet on all
previous filters that must be handled. To do so, the function
'filter_change_next_size' must be called, passing the size variation. In the
same spirit, if a filter alter forwarded data, it must call the function
'filter_change_forward_size'. 'filter_change_next_size' can be called in
'http_data' and 'tcp_data' callbacks and only these ones. And
'filter_change_forward_size' can be called in 'http_forward_data' and
'tcp_forward_data' callbacks and only these ones. The data changes are the
filter responsability, but with some limitation. It must not change already
parsed/forwarded data or data that previous filters have not parsed/forwarded
yet.
Because filters can be used on backends, when we the backend is set for a
stream, we add filters defined for this backend in the filter list of the
stream. But we must only do that when the backend and the frontend of the stream
are not the same. Else same filters are added a second time leading to undefined
behavior.
The HTTP compression code had to be moved.
So it simplifies http_response_forward_body function. To do so, the way the data
are forwarded has changed. Now, a filter (and only one) can forward data. In a
commit to come, this limitation will be removed to let all filters take part to
data forwarding. There are 2 new functions that filters should use to deal with
this feature:
* flt_set_http_data_forwarder: This function sets the filter (using its id)
that will forward data for the specified HTTP message. It is possible if it
was not already set by another filter _AND_ if no data was yet forwarded
(msg->msg_state <= HTTP_MSG_BODY). It returns -1 if an error occurs.
* flt_http_data_forwarder: This function returns the filter id that will
forward data for the specified HTTP message. If there is no forwarder set, it
returns -1.
When an HTTP data forwarder is set for the response, the HTTP compression is
disabled. Of course, this is not definitive.
2015-04-30 05:48:27 -04:00
goto out_fail_accept ;
2010-06-01 11:45:26 -04:00
/* finish initialization of the accepted file descriptor */
2017-09-13 12:30:23 -04:00
if ( cs )
cs_want_recv ( cs ) ;
2015-04-04 19:33:13 -04:00
else if ( appctx )
2015-04-21 13:23:39 -04:00
si_applet_want_get ( & s - > si [ 0 ] ) ;
2010-06-01 11:45:26 -04:00
2015-04-05 12:19:23 -04:00
if ( sess - > fe - > accept & & sess - > fe - > accept ( s ) < 0 )
2015-04-05 05:52:08 -04:00
goto out_fail_accept ;
2010-06-01 11:45:26 -04:00
/* it is important not to call the wakeup function directly but to
* pass through task_wakeup ( ) , because this one knows how to apply
2017-05-29 09:26:51 -04:00
* priorities to tasks . Using multi thread we must be sure that
* stream is fully initialized before calling task_wakeup . So
* the caller must handle the task_wakeup
2010-06-01 11:45:26 -04:00
*/
2015-04-05 06:00:52 -04:00
return s ;
2010-06-01 11:45:26 -04:00
/* Error unrolling */
2015-04-05 05:52:08 -04:00
out_fail_accept :
2015-11-05 07:35:03 -05:00
flt_stream_release ( s , 0 ) ;
2017-08-28 10:22:54 -04:00
task_free ( t ) ;
out_fail_alloc :
2014-11-25 11:10:33 -05:00
LIST_DEL ( & s - > list ) ;
2015-04-04 12:08:21 -04:00
pool_free2 ( pool2_stream , s ) ;
2015-04-05 06:00:52 -04:00
return NULL ;
2010-06-01 11:45:26 -04:00
}
2006-06-25 20:48:02 -04:00
/*
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* frees the context associated to a stream . It must have been removed first .
2006-06-25 20:48:02 -04:00
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static void stream_free ( struct stream * s )
2006-06-25 20:48:02 -04:00
{
2015-04-03 13:19:59 -04:00
struct session * sess = strm_sess ( s ) ;
struct proxy * fe = sess - > fe ;
2008-12-07 14:16:23 -05:00
struct bref * bref , * back ;
2017-09-13 12:30:23 -04:00
struct conn_stream * cli_cs = objt_cs ( s - > si [ 0 ] . end ) ;
2010-06-06 12:28:49 -04:00
int i ;
2007-01-07 09:46:13 -05:00
2006-06-25 20:48:02 -04:00
if ( s - > pend_pos )
pendconn_free ( s - > pend_pos ) ;
2008-12-04 03:33:58 -05:00
2012-11-11 18:42:33 -05:00
if ( objt_server ( s - > target ) ) { /* there may be requests left pending in queue */
2015-04-02 19:14:29 -04:00
if ( s - > flags & SF_CURR_SESS ) {
s - > flags & = ~ SF_CURR_SESS ;
2017-06-08 08:04:45 -04:00
HA_ATOMIC_SUB ( & objt_server ( s - > target ) - > cur_sess , 1 ) ;
2008-11-11 14:20:02 -05:00
}
2012-11-11 18:42:33 -05:00
if ( may_dequeue_tasks ( objt_server ( s - > target ) , s - > be ) )
process_srv_queue ( objt_server ( s - > target ) ) ;
2008-11-11 14:20:02 -05:00
}
2008-12-04 03:33:58 -05:00
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
if ( unlikely ( s - > srv_conn ) ) {
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* the stream still has a reserved slot on a server, but
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
* it should normally be only the same as the one above ,
* so this should not happen in fact .
*/
sess_change_server ( s , NULL ) ;
}
2014-11-27 14:45:39 -05:00
if ( s - > req . pipe )
put_pipe ( s - > req . pipe ) ;
2009-01-18 15:56:21 -05:00
2014-11-27 14:45:39 -05:00
if ( s - > res . pipe )
put_pipe ( s - > res . pipe ) ;
2009-01-18 15:56:21 -05:00
MAJOR: session: implement a wait-queue for sessions who need a buffer
When a session_alloc_buffers() fails to allocate one or two buffers,
it subscribes the session to buffer_wq, and waits for another session
to release buffers. It's then removed from the queue and woken up with
TASK_WAKE_RES, and can attempt its allocation again.
We decide to try to wake as many waiters as we release buffers so
that if we release 2 and two waiters need only once, they both have
their chance. We must never come to the situation where we don't wake
enough tasks up.
It's common to release buffers after the completion of an I/O callback,
which can happen even if the I/O could not be performed due to half a
failure on memory allocation. In this situation, we don't want to move
out of the wait queue the session that was just added, otherwise it
will never get any buffer. Thus, we only force ourselves out of the
queue when freeing the session.
Note: at the moment, since session_alloc_buffers() is not used, no task
is subscribed to the wait queue.
2014-11-25 15:10:35 -05:00
/* We may still be present in the buffer wait queue */
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
if ( ! LIST_ISEMPTY ( & s - > buffer_wait . list ) ) {
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( BUF_WQ_LOCK , & buffer_wq_lock ) ;
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
LIST_DEL ( & s - > buffer_wait . list ) ;
LIST_INIT ( & s - > buffer_wait . list ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( BUF_WQ_LOCK , & buffer_wq_lock ) ;
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
}
if ( s - > req . buf - > size | | s - > res . buf - > size ) {
b_drop ( & s - > req . buf ) ;
b_drop ( & s - > res . buf ) ;
offer_buffers ( NULL , tasks_run_queue + applets_active_queue ) ;
MAJOR: session: implement a wait-queue for sessions who need a buffer
When a session_alloc_buffers() fails to allocate one or two buffers,
it subscribes the session to buffer_wq, and waits for another session
to release buffers. It's then removed from the queue and woken up with
TASK_WAKE_RES, and can attempt its allocation again.
We decide to try to wake as many waiters as we release buffers so
that if we release 2 and two waiters need only once, they both have
their chance. We must never come to the situation where we don't wake
enough tasks up.
It's common to release buffers after the completion of an I/O callback,
which can happen even if the I/O could not be performed due to half a
failure on memory allocation. In this situation, we don't want to move
out of the wait queue the session that was just added, otherwise it
will never get any buffer. Thus, we only force ourselves out of the
queue when freeing the session.
Note: at the moment, since session_alloc_buffers() is not used, no task
is subscribed to the wait queue.
2014-11-25 15:10:35 -05:00
}
2012-10-12 17:49:43 -04:00
2016-12-17 06:45:32 -05:00
hlua_ctx_destroy ( s - > hlua ) ;
s - > hlua = NULL ;
2015-04-03 17:46:31 -04:00
if ( s - > txn )
http_end_txn ( s ) ;
2010-01-07 16:51:47 -05:00
2012-10-12 11:50:05 -04:00
/* ensure the client-side transport layer is destroyed */
2017-10-08 05:33:44 -04:00
if ( cli_cs )
cs_close ( cli_cs ) ;
2012-10-12 11:50:05 -04:00
2010-06-06 12:28:49 -04:00
for ( i = 0 ; i < s - > store_count ; i + + ) {
if ( ! s - > store [ i ] . ts )
continue ;
stksess_free ( s - > store [ i ] . table , s - > store [ i ] . ts ) ;
s - > store [ i ] . ts = NULL ;
}
2015-04-03 17:46:31 -04:00
if ( s - > txn ) {
pool_free2 ( pool2_hdr_idx , s - > txn - > hdr_idx . v ) ;
pool_free2 ( pool2_http_txn , s - > txn ) ;
s - > txn = NULL ;
}
MAJOR: filters: Add filters support
This patch adds the support of filters in HAProxy. The main idea is to have a
way to "easely" extend HAProxy by adding some "modules", called filters, that
will be able to change HAProxy behavior in a programmatic way.
To do so, many entry points has been added in code to let filters to hook up to
different steps of the processing. A filter must define a flt_ops sutrctures
(see include/types/filters.h for details). This structure contains all available
callbacks that a filter can define:
struct flt_ops {
/*
* Callbacks to manage the filter lifecycle
*/
int (*init) (struct proxy *p);
void (*deinit)(struct proxy *p);
int (*check) (struct proxy *p);
/*
* Stream callbacks
*/
void (*stream_start) (struct stream *s);
void (*stream_accept) (struct stream *s);
void (*session_establish)(struct stream *s);
void (*stream_stop) (struct stream *s);
/*
* HTTP callbacks
*/
int (*http_start) (struct stream *s, struct http_msg *msg);
int (*http_start_body) (struct stream *s, struct http_msg *msg);
int (*http_start_chunk) (struct stream *s, struct http_msg *msg);
int (*http_data) (struct stream *s, struct http_msg *msg);
int (*http_last_chunk) (struct stream *s, struct http_msg *msg);
int (*http_end_chunk) (struct stream *s, struct http_msg *msg);
int (*http_chunk_trailers)(struct stream *s, struct http_msg *msg);
int (*http_end_body) (struct stream *s, struct http_msg *msg);
void (*http_end) (struct stream *s, struct http_msg *msg);
void (*http_reset) (struct stream *s, struct http_msg *msg);
int (*http_pre_process) (struct stream *s, struct http_msg *msg);
int (*http_post_process) (struct stream *s, struct http_msg *msg);
void (*http_reply) (struct stream *s, short status,
const struct chunk *msg);
};
To declare and use a filter, in the configuration, the "filter" keyword must be
used in a listener/frontend section:
frontend test
...
filter <FILTER-NAME> [OPTIONS...]
The filter referenced by the <FILTER-NAME> must declare a configuration parser
on its own name to fill flt_ops and filter_conf field in the proxy's
structure. An exemple will be provided later to make it perfectly clear.
For now, filters cannot be used in backend section. But this is only a matter of
time. Documentation will also be added later. This is the first commit of a long
list about filters.
It is possible to have several filters on the same listener/frontend. These
filters are stored in an array of at most MAX_FILTERS elements (define in
include/types/filters.h). Again, this will be replaced later by a list of
filters.
The filter API has been highly refactored. Main changes are:
* Now, HA supports an infinite number of filters per proxy. To do so, filters
are stored in list.
* Because filters are stored in list, filters state has been moved from the
channel structure to the filter structure. This is cleaner because there is no
more info about filters in channel structure.
* It is possible to defined filters on backends only. For such filters,
stream_start/stream_stop callbacks are not called. Of course, it is possible
to mix frontend and backend filters.
* Now, TCP streams are also filtered. All callbacks without the 'http_' prefix
are called for all kind of streams. In addition, 2 new callbacks were added to
filter data exchanged through a TCP stream:
- tcp_data: it is called when new data are available or when old unprocessed
data are still waiting.
- tcp_forward_data: it is called when some data can be consumed.
* New callbacks attached to channel were added:
- channel_start_analyze: it is called when a filter is ready to process data
exchanged through a channel. 2 new analyzers (a frontend and a backend)
are attached to channels to call this callback. For a frontend filter, it
is called before any other analyzer. For a backend filter, it is called
when a backend is attached to a stream. So some processing cannot be
filtered in that case.
- channel_analyze: it is called before each analyzer attached to a channel,
expects analyzers responsible for data sending.
- channel_end_analyze: it is called when all other analyzers have finished
their processing. A new analyzers is attached to channels to call this
callback. For a TCP stream, this is always the last one called. For a HTTP
one, the callback is called when a request/response ends, so it is called
one time for each request/response.
* 'session_established' callback has been removed. Everything that is done in
this callback can be handled by 'channel_start_analyze' on the response
channel.
* 'http_pre_process' and 'http_post_process' callbacks have been replaced by
'channel_analyze'.
* 'http_start' callback has been replaced by 'http_headers'. This new one is
called just before headers sending and parsing of the body.
* 'http_end' callback has been replaced by 'channel_end_analyze'.
* It is possible to set a forwarder for TCP channels. It was already possible to
do it for HTTP ones.
* Forwarders can partially consumed forwardable data. For this reason a new
HTTP message state was added before HTTP_MSG_DONE : HTTP_MSG_ENDING.
Now all filters can define corresponding callbacks (http_forward_data
and tcp_forward_data). Each filter owns 2 offsets relative to buf->p, next and
forward, to track, respectively, input data already parsed but not forwarded yet
by the filter and parsed data considered as forwarded by the filter. A any time,
we have the warranty that a filter cannot parse or forward more input than
previous ones. And, of course, it cannot forward more input than it has
parsed. 2 macros has been added to retrieve these offets: FLT_NXT and FLT_FWD.
In addition, 2 functions has been added to change the 'next size' and the
'forward size' of a filter. When a filter parses input data, it can alter these
data, so the size of these data can vary. This action has an effet on all
previous filters that must be handled. To do so, the function
'filter_change_next_size' must be called, passing the size variation. In the
same spirit, if a filter alter forwarded data, it must call the function
'filter_change_forward_size'. 'filter_change_next_size' can be called in
'http_data' and 'tcp_data' callbacks and only these ones. And
'filter_change_forward_size' can be called in 'http_forward_data' and
'tcp_forward_data' callbacks and only these ones. The data changes are the
filter responsability, but with some limitation. It must not change already
parsed/forwarded data or data that previous filters have not parsed/forwarded
yet.
Because filters can be used on backends, when we the backend is set for a
stream, we add filters defined for this backend in the filter list of the
stream. But we must only do that when the backend and the frontend of the stream
are not the same. Else same filters are added a second time leading to undefined
behavior.
The HTTP compression code had to be moved.
So it simplifies http_response_forward_body function. To do so, the way the data
are forwarded has changed. Now, a filter (and only one) can forward data. In a
commit to come, this limitation will be removed to let all filters take part to
data forwarding. There are 2 new functions that filters should use to deal with
this feature:
* flt_set_http_data_forwarder: This function sets the filter (using its id)
that will forward data for the specified HTTP message. It is possible if it
was not already set by another filter _AND_ if no data was yet forwarded
(msg->msg_state <= HTTP_MSG_BODY). It returns -1 if an error occurs.
* flt_http_data_forwarder: This function returns the filter id that will
forward data for the specified HTTP message. If there is no forwarder set, it
returns -1.
When an HTTP data forwarder is set for the response, the HTTP compression is
disabled. Of course, this is not definitive.
2015-04-30 05:48:27 -04:00
flt_stream_stop ( s ) ;
2015-11-05 07:35:03 -05:00
flt_stream_release ( s , 0 ) ;
MAJOR: filters: Add filters support
This patch adds the support of filters in HAProxy. The main idea is to have a
way to "easely" extend HAProxy by adding some "modules", called filters, that
will be able to change HAProxy behavior in a programmatic way.
To do so, many entry points has been added in code to let filters to hook up to
different steps of the processing. A filter must define a flt_ops sutrctures
(see include/types/filters.h for details). This structure contains all available
callbacks that a filter can define:
struct flt_ops {
/*
* Callbacks to manage the filter lifecycle
*/
int (*init) (struct proxy *p);
void (*deinit)(struct proxy *p);
int (*check) (struct proxy *p);
/*
* Stream callbacks
*/
void (*stream_start) (struct stream *s);
void (*stream_accept) (struct stream *s);
void (*session_establish)(struct stream *s);
void (*stream_stop) (struct stream *s);
/*
* HTTP callbacks
*/
int (*http_start) (struct stream *s, struct http_msg *msg);
int (*http_start_body) (struct stream *s, struct http_msg *msg);
int (*http_start_chunk) (struct stream *s, struct http_msg *msg);
int (*http_data) (struct stream *s, struct http_msg *msg);
int (*http_last_chunk) (struct stream *s, struct http_msg *msg);
int (*http_end_chunk) (struct stream *s, struct http_msg *msg);
int (*http_chunk_trailers)(struct stream *s, struct http_msg *msg);
int (*http_end_body) (struct stream *s, struct http_msg *msg);
void (*http_end) (struct stream *s, struct http_msg *msg);
void (*http_reset) (struct stream *s, struct http_msg *msg);
int (*http_pre_process) (struct stream *s, struct http_msg *msg);
int (*http_post_process) (struct stream *s, struct http_msg *msg);
void (*http_reply) (struct stream *s, short status,
const struct chunk *msg);
};
To declare and use a filter, in the configuration, the "filter" keyword must be
used in a listener/frontend section:
frontend test
...
filter <FILTER-NAME> [OPTIONS...]
The filter referenced by the <FILTER-NAME> must declare a configuration parser
on its own name to fill flt_ops and filter_conf field in the proxy's
structure. An exemple will be provided later to make it perfectly clear.
For now, filters cannot be used in backend section. But this is only a matter of
time. Documentation will also be added later. This is the first commit of a long
list about filters.
It is possible to have several filters on the same listener/frontend. These
filters are stored in an array of at most MAX_FILTERS elements (define in
include/types/filters.h). Again, this will be replaced later by a list of
filters.
The filter API has been highly refactored. Main changes are:
* Now, HA supports an infinite number of filters per proxy. To do so, filters
are stored in list.
* Because filters are stored in list, filters state has been moved from the
channel structure to the filter structure. This is cleaner because there is no
more info about filters in channel structure.
* It is possible to defined filters on backends only. For such filters,
stream_start/stream_stop callbacks are not called. Of course, it is possible
to mix frontend and backend filters.
* Now, TCP streams are also filtered. All callbacks without the 'http_' prefix
are called for all kind of streams. In addition, 2 new callbacks were added to
filter data exchanged through a TCP stream:
- tcp_data: it is called when new data are available or when old unprocessed
data are still waiting.
- tcp_forward_data: it is called when some data can be consumed.
* New callbacks attached to channel were added:
- channel_start_analyze: it is called when a filter is ready to process data
exchanged through a channel. 2 new analyzers (a frontend and a backend)
are attached to channels to call this callback. For a frontend filter, it
is called before any other analyzer. For a backend filter, it is called
when a backend is attached to a stream. So some processing cannot be
filtered in that case.
- channel_analyze: it is called before each analyzer attached to a channel,
expects analyzers responsible for data sending.
- channel_end_analyze: it is called when all other analyzers have finished
their processing. A new analyzers is attached to channels to call this
callback. For a TCP stream, this is always the last one called. For a HTTP
one, the callback is called when a request/response ends, so it is called
one time for each request/response.
* 'session_established' callback has been removed. Everything that is done in
this callback can be handled by 'channel_start_analyze' on the response
channel.
* 'http_pre_process' and 'http_post_process' callbacks have been replaced by
'channel_analyze'.
* 'http_start' callback has been replaced by 'http_headers'. This new one is
called just before headers sending and parsing of the body.
* 'http_end' callback has been replaced by 'channel_end_analyze'.
* It is possible to set a forwarder for TCP channels. It was already possible to
do it for HTTP ones.
* Forwarders can partially consumed forwardable data. For this reason a new
HTTP message state was added before HTTP_MSG_DONE : HTTP_MSG_ENDING.
Now all filters can define corresponding callbacks (http_forward_data
and tcp_forward_data). Each filter owns 2 offsets relative to buf->p, next and
forward, to track, respectively, input data already parsed but not forwarded yet
by the filter and parsed data considered as forwarded by the filter. A any time,
we have the warranty that a filter cannot parse or forward more input than
previous ones. And, of course, it cannot forward more input than it has
parsed. 2 macros has been added to retrieve these offets: FLT_NXT and FLT_FWD.
In addition, 2 functions has been added to change the 'next size' and the
'forward size' of a filter. When a filter parses input data, it can alter these
data, so the size of these data can vary. This action has an effet on all
previous filters that must be handled. To do so, the function
'filter_change_next_size' must be called, passing the size variation. In the
same spirit, if a filter alter forwarded data, it must call the function
'filter_change_forward_size'. 'filter_change_next_size' can be called in
'http_data' and 'tcp_data' callbacks and only these ones. And
'filter_change_forward_size' can be called in 'http_forward_data' and
'tcp_forward_data' callbacks and only these ones. The data changes are the
filter responsability, but with some limitation. It must not change already
parsed/forwarded data or data that previous filters have not parsed/forwarded
yet.
Because filters can be used on backends, when we the backend is set for a
stream, we add filters defined for this backend in the filter list of the
stream. But we must only do that when the backend and the frontend of the stream
are not the same. Else same filters are added a second time leading to undefined
behavior.
The HTTP compression code had to be moved.
So it simplifies http_response_forward_body function. To do so, the way the data
are forwarded has changed. Now, a filter (and only one) can forward data. In a
commit to come, this limitation will be removed to let all filters take part to
data forwarding. There are 2 new functions that filters should use to deal with
this feature:
* flt_set_http_data_forwarder: This function sets the filter (using its id)
that will forward data for the specified HTTP message. It is possible if it
was not already set by another filter _AND_ if no data was yet forwarded
(msg->msg_state <= HTTP_MSG_BODY). It returns -1 if an error occurs.
* flt_http_data_forwarder: This function returns the filter id that will
forward data for the specified HTTP message. If there is no forwarder set, it
returns -1.
When an HTTP data forwarder is set for the response, the HTTP compression is
disabled. Of course, this is not definitive.
2015-04-30 05:48:27 -04:00
2007-10-16 11:34:28 -04:00
if ( fe ) {
2015-04-03 16:16:32 -04:00
pool_free2 ( fe - > rsp_cap_pool , s - > res_cap ) ;
pool_free2 ( fe - > req_cap_pool , s - > req_cap ) ;
2006-06-25 20:48:02 -04:00
}
2009-12-22 09:03:09 -05:00
2015-06-06 13:29:07 -04:00
/* Cleanup all variable contexts. */
2016-03-10 10:33:04 -05:00
vars_prune ( & s - > vars_txn , s - > sess , s ) ;
vars_prune ( & s - > vars_reqres , s - > sess , s ) ;
2015-06-06 13:29:07 -04:00
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_store_counters ( s ) ;
2010-06-14 15:04:55 -04:00
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( STRMS_LOCK , & streams_lock ) ;
2008-12-07 14:16:23 -05:00
list_for_each_entry_safe ( bref , back , & s - > back_refs , users ) {
2009-02-22 09:17:24 -05:00
/* we have to unlink all watchers. We must not relink them if
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* this stream was the last one in the list .
2009-02-22 09:17:24 -05:00
*/
2008-12-07 14:16:23 -05:00
LIST_DEL ( & bref - > users ) ;
2009-02-22 09:17:24 -05:00
LIST_INIT ( & bref - > users ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
if ( s - > list . n ! = & streams )
LIST_ADDQ ( & LIST_ELEM ( s - > list . n , struct stream * , list ) - > back_refs , & bref - > users ) ;
2008-12-07 14:16:23 -05:00
bref - > ref = s - > list . n ;
}
2008-11-23 13:53:55 -05:00
LIST_DEL ( & s - > list ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2017-06-30 10:23:45 -04:00
2013-10-11 13:34:20 -04:00
si_release_endpoint ( & s - > si [ 1 ] ) ;
si_release_endpoint ( & s - > si [ 0 ] ) ;
2015-04-03 08:10:06 -04:00
/* FIXME: for now we have a 1:1 relation between stream and session so
* the stream must free the session .
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
pool_free2 ( pool2_stream , s ) ;
2007-07-11 04:42:35 -04:00
/* We may want to free the maximum amount of pools if the proxy is stopping */
2007-10-16 11:34:28 -04:00
if ( fe & & unlikely ( fe - > state = = PR_STSTOPPED ) ) {
2012-10-12 17:49:43 -04:00
pool_flush2 ( pool2_buffer ) ;
2015-04-03 16:55:33 -04:00
pool_flush2 ( pool2_http_txn ) ;
2011-10-24 12:15:04 -04:00
pool_flush2 ( pool2_hdr_idx ) ;
2008-08-03 11:41:33 -04:00
pool_flush2 ( pool2_requri ) ;
pool_flush2 ( pool2_capture ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
pool_flush2 ( pool2_stream ) ;
2015-04-03 08:10:06 -04:00
pool_flush2 ( pool2_session ) ;
2014-11-13 10:46:28 -05:00
pool_flush2 ( pool2_connection ) ;
pool_flush2 ( pool2_pendconn ) ;
2008-08-03 11:41:33 -04:00
pool_flush2 ( fe - > req_cap_pool ) ;
pool_flush2 ( fe - > rsp_cap_pool ) ;
2007-07-11 04:42:35 -04:00
}
2007-05-13 13:43:47 -04:00
}
2014-11-25 13:46:36 -05:00
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* Allocates a work buffer for stream <s>. It is meant to be called inside
* process_stream ( ) . It will only allocate the side needed for the function
2015-04-20 09:52:18 -04:00
* to work fine , which is the response buffer so that an error message may be
* built and returned . Response buffers may be allocated from the reserve , this
* is critical to ensure that a response may always flow and will never block a
* server from releasing a connection . Returns 0 in case of failure , non - zero
* otherwise .
2014-11-25 13:46:36 -05:00
*/
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
static int stream_alloc_work_buffer ( struct stream * s )
2014-11-25 13:46:36 -05:00
{
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
if ( ! LIST_ISEMPTY ( & s - > buffer_wait . list ) ) {
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( BUF_WQ_LOCK , & buffer_wq_lock ) ;
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
LIST_DEL ( & s - > buffer_wait . list ) ;
LIST_INIT ( & s - > buffer_wait . list ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( BUF_WQ_LOCK , & buffer_wq_lock ) ;
MAJOR: session: implement a wait-queue for sessions who need a buffer
When a session_alloc_buffers() fails to allocate one or two buffers,
it subscribes the session to buffer_wq, and waits for another session
to release buffers. It's then removed from the queue and woken up with
TASK_WAKE_RES, and can attempt its allocation again.
We decide to try to wake as many waiters as we release buffers so
that if we release 2 and two waiters need only once, they both have
their chance. We must never come to the situation where we don't wake
enough tasks up.
It's common to release buffers after the completion of an I/O callback,
which can happen even if the I/O could not be performed due to half a
failure on memory allocation. In this situation, we don't want to move
out of the wait queue the session that was just added, otherwise it
will never get any buffer. Thus, we only force ourselves out of the
queue when freeing the session.
Note: at the moment, since session_alloc_buffers() is not used, no task
is subscribed to the wait queue.
2014-11-25 15:10:35 -05:00
}
2014-11-25 13:46:36 -05:00
2015-04-20 09:52:18 -04:00
if ( b_alloc_margin ( & s - > res . buf , 0 ) )
2014-11-25 13:46:36 -05:00
return 1 ;
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( BUF_WQ_LOCK , & buffer_wq_lock ) ;
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
LIST_ADDQ ( & buffer_wq , & s - > buffer_wait . list ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( BUF_WQ_LOCK , & buffer_wq_lock ) ;
2014-11-25 13:46:36 -05:00
return 0 ;
}
/* releases unused buffers after processing. Typically used at the end of the
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
* update ( ) functions . It will try to wake up as many tasks / applets as the
* number of buffers that it releases . In practice , most often streams are
* blocked on a single buffer , so it makes sense to try to wake two up when two
* buffers are released at once .
2014-11-25 13:46:36 -05:00
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
void stream_release_buffers ( struct stream * s )
2014-11-25 13:46:36 -05:00
{
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
int offer = 0 ;
2014-11-25 13:46:36 -05:00
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
if ( s - > req . buf - > size & & buffer_empty ( s - > req . buf ) ) {
offer = 1 ;
b_free ( & s - > req . buf ) ;
}
if ( s - > res . buf - > size & & buffer_empty ( s - > res . buf ) ) {
offer = 1 ;
2014-11-27 14:45:39 -05:00
b_free ( & s - > res . buf ) ;
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
}
2014-11-25 13:46:36 -05:00
MAJOR: session: implement a wait-queue for sessions who need a buffer
When a session_alloc_buffers() fails to allocate one or two buffers,
it subscribes the session to buffer_wq, and waits for another session
to release buffers. It's then removed from the queue and woken up with
TASK_WAKE_RES, and can attempt its allocation again.
We decide to try to wake as many waiters as we release buffers so
that if we release 2 and two waiters need only once, they both have
their chance. We must never come to the situation where we don't wake
enough tasks up.
It's common to release buffers after the completion of an I/O callback,
which can happen even if the I/O could not be performed due to half a
failure on memory allocation. In this situation, we don't want to move
out of the wait queue the session that was just added, otherwise it
will never get any buffer. Thus, we only force ourselves out of the
queue when freeing the session.
Note: at the moment, since session_alloc_buffers() is not used, no task
is subscribed to the wait queue.
2014-11-25 15:10:35 -05:00
/* if we're certain to have at least 1 buffer available, and there is
* someone waiting , we can wake up a waiter and offer them .
*/
BUG/MAJOR: Fix how the list of entities waiting for a buffer is handled
When an entity tries to get a buffer, if it cannot be allocted, for example
because the number of buffers which may be allocated per process is limited,
this entity is added in a list (called <buffer_wq>) and wait for an available
buffer.
Historically, the <buffer_wq> list was logically attached to streams because it
were the only entities likely to be added in it. Now, applets can also be
waiting for a free buffer. And with filters, we could imagine to have more other
entities waiting for a buffer. So it make sense to have a generic list.
Anyway, with the current design there is a bug. When an applet failed to get a
buffer, it will wait. But we add the stream attached to the applet in
<buffer_wq>, instead of the applet itself. So when a buffer is available, we
wake up the stream and not the waiting applet. So, it is possible to have
waiting applets and never awakened.
So, now, <buffer_wq> is independant from streams. And we really add the waiting
entity in <buffer_wq>. To be generic, the entity is responsible to define the
callback used to awaken it.
In addition, applets will still request an input buffer when they become
active. But they will not be sleeped anymore if no buffer are available. So this
is the responsibility to the applet I/O handler to check if this buffer is
allocated or not. This way, an applet can decide if this buffer is required or
not and can do additional processing if not.
[wt: backport to 1.7 and 1.6]
2016-12-09 11:30:18 -05:00
if ( offer )
offer_buffers ( s , tasks_run_queue + applets_active_queue ) ;
2014-11-25 13:46:36 -05:00
}
2007-05-13 13:43:47 -04:00
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
int init_stream ( )
2007-05-13 13:43:47 -04:00
{
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
LIST_INIT ( & streams ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_INIT ( & streams_lock ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
pool2_stream = create_pool ( " stream " , sizeof ( struct stream ) , MEM_F_SHARED ) ;
return pool2_stream ! = NULL ;
2006-06-25 20:48:02 -04:00
}
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
void stream_process_counters ( struct stream * s )
2007-11-26 14:15:35 -05:00
{
2015-04-03 08:46:27 -04:00
struct session * sess = s - > sess ;
2007-11-24 16:12:47 -05:00
unsigned long long bytes ;
2015-06-15 12:29:57 -04:00
void * ptr1 , * ptr2 ;
2017-06-13 13:37:32 -04:00
struct stksess * ts ;
2012-12-09 09:55:40 -05:00
int i ;
2007-11-24 16:12:47 -05:00
2014-11-27 14:45:39 -05:00
bytes = s - > req . total - s - > logs . bytes_in ;
s - > logs . bytes_in = s - > req . total ;
if ( bytes ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . bytes_in , bytes ) ;
HA_ATOMIC_ADD ( & s - > be - > be_counters . bytes_in , bytes ) ;
2009-10-04 09:43:17 -04:00
2014-11-27 14:45:39 -05:00
if ( objt_server ( s - > target ) )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & objt_server ( s - > target ) - > counters . bytes_in , bytes ) ;
2010-06-18 12:33:32 -04:00
2015-04-03 08:46:27 -04:00
if ( sess - > listener & & sess - > listener - > counters )
2017-05-30 09:36:50 -04:00
HA_ATOMIC_ADD ( & sess - > listener - > counters - > bytes_in , bytes ) ;
2010-06-20 05:56:30 -04:00
2014-11-27 14:45:39 -05:00
for ( i = 0 ; i < MAX_SESS_STKCTR ; i + + ) {
2015-04-04 10:29:12 -04:00
struct stkctr * stkctr = & s - > stkctr [ i ] ;
2017-06-13 13:37:32 -04:00
ts = stkctr_entry ( stkctr ) ;
if ( ! ts ) {
2015-04-04 10:29:12 -04:00
stkctr = & sess - > stkctr [ i ] ;
2017-06-13 13:37:32 -04:00
ts = stkctr_entry ( stkctr ) ;
if ( ! ts )
2015-04-04 10:29:12 -04:00
continue ;
}
2010-06-20 05:56:30 -04:00
2017-11-07 04:42:54 -05:00
HA_RWLOCK_WRLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2017-06-13 13:37:32 -04:00
ptr1 = stktable_data_ptr ( stkctr - > table , ts , STKTABLE_DT_BYTES_IN_CNT ) ;
2015-06-15 12:29:57 -04:00
if ( ptr1 )
stktable_data_cast ( ptr1 , bytes_in_cnt ) + = bytes ;
2014-11-27 14:45:39 -05:00
2017-06-13 13:37:32 -04:00
ptr2 = stktable_data_ptr ( stkctr - > table , ts , STKTABLE_DT_BYTES_IN_RATE ) ;
2015-06-15 12:29:57 -04:00
if ( ptr2 )
update_freq_ctr_period ( & stktable_data_cast ( ptr2 , bytes_in_rate ) ,
2015-04-04 10:29:12 -04:00
stkctr - > table - > data_arg [ STKTABLE_DT_BYTES_IN_RATE ] . u , bytes ) ;
2017-11-07 04:42:54 -05:00
HA_RWLOCK_WRUNLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2015-06-15 12:29:57 -04:00
/* If data was modified, we need to touch to re-schedule sync */
if ( ptr1 | | ptr2 )
2017-06-13 13:37:32 -04:00
stktable_touch_local ( stkctr - > table , ts , 0 ) ;
2007-11-26 14:15:35 -05:00
}
2007-11-24 16:12:47 -05:00
}
2014-11-27 14:45:39 -05:00
bytes = s - > res . total - s - > logs . bytes_out ;
s - > logs . bytes_out = s - > res . total ;
if ( bytes ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . bytes_out , bytes ) ;
HA_ATOMIC_ADD ( & s - > be - > be_counters . bytes_out , bytes ) ;
2009-10-04 09:43:17 -04:00
2014-11-27 14:45:39 -05:00
if ( objt_server ( s - > target ) )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & objt_server ( s - > target ) - > counters . bytes_out , bytes ) ;
2010-08-03 10:29:52 -04:00
2015-04-03 08:46:27 -04:00
if ( sess - > listener & & sess - > listener - > counters )
2017-05-30 09:36:50 -04:00
HA_ATOMIC_ADD ( & sess - > listener - > counters - > bytes_out , bytes ) ;
2010-06-20 05:56:30 -04:00
2014-11-27 14:45:39 -05:00
for ( i = 0 ; i < MAX_SESS_STKCTR ; i + + ) {
2015-04-04 10:29:12 -04:00
struct stkctr * stkctr = & s - > stkctr [ i ] ;
2017-06-13 13:37:32 -04:00
ts = stkctr_entry ( stkctr ) ;
if ( ! ts ) {
2015-04-04 10:29:12 -04:00
stkctr = & sess - > stkctr [ i ] ;
2017-06-13 13:37:32 -04:00
ts = stkctr_entry ( stkctr ) ;
if ( ! ts )
2015-04-04 10:29:12 -04:00
continue ;
}
2010-06-20 05:56:30 -04:00
2017-11-07 04:42:54 -05:00
HA_RWLOCK_WRLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2017-06-13 13:37:32 -04:00
ptr1 = stktable_data_ptr ( stkctr - > table , ts , STKTABLE_DT_BYTES_OUT_CNT ) ;
2015-06-15 12:29:57 -04:00
if ( ptr1 )
stktable_data_cast ( ptr1 , bytes_out_cnt ) + = bytes ;
2014-11-27 14:45:39 -05:00
2017-06-13 13:37:32 -04:00
ptr2 = stktable_data_ptr ( stkctr - > table , ts , STKTABLE_DT_BYTES_OUT_RATE ) ;
2015-06-15 12:29:57 -04:00
if ( ptr2 )
update_freq_ctr_period ( & stktable_data_cast ( ptr2 , bytes_out_rate ) ,
2015-04-04 10:29:12 -04:00
stkctr - > table - > data_arg [ STKTABLE_DT_BYTES_OUT_RATE ] . u , bytes ) ;
2017-11-07 04:42:54 -05:00
HA_RWLOCK_WRUNLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2015-06-15 12:29:57 -04:00
/* If data was modified, we need to touch to re-schedule sync */
if ( ptr1 | | ptr2 )
2017-06-13 13:37:32 -04:00
stktable_touch_local ( stkctr - > table , stkctr_entry ( stkctr ) , 0 ) ;
2007-11-26 14:15:35 -05:00
}
2007-11-24 16:12:47 -05:00
}
}
2006-06-25 20:48:02 -04:00
2008-11-30 12:47:21 -05:00
/* This function is called with (si->state == SI_ST_CON) meaning that a
* connection was attempted and that the file descriptor is already allocated .
* We must check for establishment , error and abort . Possible output states
* are SI_ST_EST ( established ) , SI_ST_CER ( error ) , SI_ST_DIS ( abort ) , and
* SI_ST_CON ( no change ) . The function returns 0 if it switches to SI_ST_CER ,
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* otherwise 1. This only works with connection - based streams .
2008-11-30 12:47:21 -05:00
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static int sess_update_st_con_tcp ( struct stream * s )
2008-11-30 12:47:21 -05:00
{
2014-11-28 09:15:44 -05:00
struct stream_interface * si = & s - > si [ 1 ] ;
struct channel * req = & s - > req ;
struct channel * rep = & s - > res ;
2017-10-05 12:52:17 -04:00
struct conn_stream * srv_cs = __objt_cs ( si - > end ) ;
2008-11-30 12:47:21 -05:00
/* If we got an error, or if nothing happened and the connection timed
* out , we must give up . The CER state handler will take care of retry
* attempts and error reports .
*/
if ( unlikely ( si - > flags & ( SI_FL_EXP | SI_FL_ERR ) ) ) {
BUG/MAJOR: stream-int: don't re-arm recv if send fails
When
1) HAProxy configured to enable splice on both directions
2) After some high load, there are 2 input channels with their socket buffer
being non-empty and pipe being full at the same time, sitting in `fd_cache`
without any other fds.
The 2 channels will repeatedly be stopped for receiving (pipe full) and waken
for receiving (data in socket), thus getting out and in of `fd_cache`, making
their fd swapping location in `fd_cache`.
There is a `if (entry < fd_cache_num && fd_cache[entry] != fd) continue;`
statement in `fd_process_cached_events` to prevent frequent polling, but since
the only 2 fds are constantly swapping location, `fd_cache[entry] != fd` will
always hold true, thus HAProxy can't make any progress.
The root cause of the issue is dual :
- there is a single fd_cache, for next events and for the ones being
processed, while using two distinct arrays would avoid the problem.
- the write side of the stream interface wakes the read side up even
when it couldn't write, and this one really is a bug.
Due to CF_WRITE_PARTIAL not being cleared during fast forwarding, a failed
send() attempt will still cause ->chk_rcv() to be called on the other side,
re-creating an entry for its connection fd in the cache, causing the same
sequence to be repeated indefinitely without any opportunity to make progress.
CF_WRITE_PARTIAL used to be used for what is present in these tests : check
if a recent write operation was performed. It's part of the CF_WRITE_ACTIVITY
set and is tested to check if timeouts need to be updated. It's also used to
detect if a failed connect() may be retried.
What this patch does is use CF_WROTE_DATA() to check for a successful write
for connection retransmits, and to clear CF_WRITE_PARTIAL before preparing
to send in stream_int_notify(). This way, timeouts are still updated each
time a write succeeds, but chk_rcv() won't be called anymore after a failed
write.
It seems the fix is required all the way down to 1.5.
Without this patch, the only workaround at this point is to disable splicing
in at least one direction. Strictly speaking, splicing is not absolutely
required, as regular forwarding could theorically cause the issue to happen
if the timing is appropriate, but in practice it appears impossible to
reproduce it without splicing, and even with splicing it may vary.
The following config manages to reproduce it after a few attempts (haproxy
going 100% CPU and having to be killed) :
global
maxpipes 50000
maxconn 10000
listen srv1
option splice-request
option splice-response
bind :8001
server s1 127.0.0.1:8002
server$ tcploop 8002 L N20 A R10 S1000000 R10 S1000000 R10 S1000000 R10 S1000000 R10 S1000000
client$ tcploop 8001 N20 C T S1000000 R10 J
2017-09-15 02:56:40 -04:00
if ( unlikely ( req - > flags & CF_WROTE_DATA ) ) {
2012-10-29 17:41:31 -04:00
/* Some data were sent past the connection establishment,
* so we need to pretend we ' re established to log correctly
* and let later states handle the failure .
*/
si - > state = SI_ST_EST ;
si - > err_type = SI_ET_DATA_ERR ;
2014-11-28 09:26:12 -05:00
rep - > flags | = CF_READ_ERROR | CF_WRITE_ERROR ;
2012-10-29 17:41:31 -04:00
return 1 ;
}
2009-03-28 05:47:26 -04:00
si - > exp = TICK_ETERNITY ;
2008-11-30 12:47:21 -05:00
si - > state = SI_ST_CER ;
2017-09-13 12:30:23 -04:00
/* XXX cognet: do we really want to kill the connection here ?
* Probably not for multiple streams .
*/
2017-10-05 12:52:17 -04:00
cs_close ( srv_cs ) ;
2012-12-08 02:44:02 -05:00
2008-11-30 12:47:21 -05:00
if ( si - > err_type )
return 0 ;
if ( si - > flags & SI_FL_ERR )
si - > err_type = SI_ET_CONN_ERR ;
else
si - > err_type = SI_ET_CONN_TO ;
return 0 ;
}
/* OK, maybe we want to abort */
BUG/MAJOR: stream-int: don't re-arm recv if send fails
When
1) HAProxy configured to enable splice on both directions
2) After some high load, there are 2 input channels with their socket buffer
being non-empty and pipe being full at the same time, sitting in `fd_cache`
without any other fds.
The 2 channels will repeatedly be stopped for receiving (pipe full) and waken
for receiving (data in socket), thus getting out and in of `fd_cache`, making
their fd swapping location in `fd_cache`.
There is a `if (entry < fd_cache_num && fd_cache[entry] != fd) continue;`
statement in `fd_process_cached_events` to prevent frequent polling, but since
the only 2 fds are constantly swapping location, `fd_cache[entry] != fd` will
always hold true, thus HAProxy can't make any progress.
The root cause of the issue is dual :
- there is a single fd_cache, for next events and for the ones being
processed, while using two distinct arrays would avoid the problem.
- the write side of the stream interface wakes the read side up even
when it couldn't write, and this one really is a bug.
Due to CF_WRITE_PARTIAL not being cleared during fast forwarding, a failed
send() attempt will still cause ->chk_rcv() to be called on the other side,
re-creating an entry for its connection fd in the cache, causing the same
sequence to be repeated indefinitely without any opportunity to make progress.
CF_WRITE_PARTIAL used to be used for what is present in these tests : check
if a recent write operation was performed. It's part of the CF_WRITE_ACTIVITY
set and is tested to check if timeouts need to be updated. It's also used to
detect if a failed connect() may be retried.
What this patch does is use CF_WROTE_DATA() to check for a successful write
for connection retransmits, and to clear CF_WRITE_PARTIAL before preparing
to send in stream_int_notify(). This way, timeouts are still updated each
time a write succeeds, but chk_rcv() won't be called anymore after a failed
write.
It seems the fix is required all the way down to 1.5.
Without this patch, the only workaround at this point is to disable splicing
in at least one direction. Strictly speaking, splicing is not absolutely
required, as regular forwarding could theorically cause the issue to happen
if the timing is appropriate, but in practice it appears impossible to
reproduce it without splicing, and even with splicing it may vary.
The following config manages to reproduce it after a few attempts (haproxy
going 100% CPU and having to be killed) :
global
maxpipes 50000
maxconn 10000
listen srv1
option splice-request
option splice-response
bind :8001
server s1 127.0.0.1:8002
server$ tcploop 8002 L N20 A R10 S1000000 R10 S1000000 R10 S1000000 R10 S1000000 R10 S1000000
client$ tcploop 8001 N20 C T S1000000 R10 J
2017-09-15 02:56:40 -04:00
if ( ! ( req - > flags & CF_WROTE_DATA ) & &
2012-12-29 18:50:35 -05:00
unlikely ( ( rep - > flags & CF_SHUTW ) | |
2012-08-27 17:14:58 -04:00
( ( req - > flags & CF_SHUTW_NOW ) & & /* FIXME: this should not prevent a connection from establishing */
BUG/MEDIUM: stream-int: Don't loss write's notifs when a stream is woken up
When a write activity is reported on a channel, it is important to keep this
information for the stream because it take part on the analyzers' triggering.
When some data are written, the flag CF_WRITE_PARTIAL is set. It participates to
the task's timeout updates and to the stream's waking. It is also used in
CF_MASK_ANALYSER mask to trigger channels anaylzers. In the past, it was cleared
by process_stream. Because of a bug (fixed in commit 95fad5ba4 ["BUG/MAJOR:
stream-int: don't re-arm recv if send fails"]), It is now cleared before each
send and in stream_int_notify. So it is possible to loss this information when
process_stream is called, preventing analyzers to be called, and possibly
leading to a stalled stream.
Today, this happens in HTTP2 when you call the stat page or when you use the
cache filter. In fact, this happens when the response is sent by an applet. In
HTTP1, everything seems to work as expected.
To fix the problem, we need to make the difference between the write activity
reported to lower layers and the one reported to the stream. So the flag
CF_WRITE_EVENT has been added to notify the stream of the write activity on a
channel. It is set when a send succedded and reset by process_stream. It is also
used in CF_MASK_ANALYSER. finally, it is checked in stream_int_notify to wake up
a stream and in channel_check_timeouts.
This bug is probably present in 1.7 but it seems to have no effect. So for now,
no needs to backport it.
2017-11-09 03:36:43 -05:00
( ( ! ( req - > flags & ( CF_WRITE_ACTIVITY | CF_WRITE_EVENT ) ) & & channel_is_empty ( req ) ) | |
2008-11-30 12:47:21 -05:00
s - > be - > options & PR_O_ABRT_CLOSE ) ) ) ) {
/* give up */
2012-05-21 10:31:45 -04:00
si_shutw ( si ) ;
2008-11-30 12:47:21 -05:00
si - > err_type | = SI_ET_CONN_ABRT ;
2009-03-15 17:34:05 -04:00
if ( s - > srv_error )
s - > srv_error ( s , si ) ;
2008-11-30 12:47:21 -05:00
return 1 ;
}
/* we need to wait a bit more if there was no activity either */
BUG/MEDIUM: stream-int: Don't loss write's notifs when a stream is woken up
When a write activity is reported on a channel, it is important to keep this
information for the stream because it take part on the analyzers' triggering.
When some data are written, the flag CF_WRITE_PARTIAL is set. It participates to
the task's timeout updates and to the stream's waking. It is also used in
CF_MASK_ANALYSER mask to trigger channels anaylzers. In the past, it was cleared
by process_stream. Because of a bug (fixed in commit 95fad5ba4 ["BUG/MAJOR:
stream-int: don't re-arm recv if send fails"]), It is now cleared before each
send and in stream_int_notify. So it is possible to loss this information when
process_stream is called, preventing analyzers to be called, and possibly
leading to a stalled stream.
Today, this happens in HTTP2 when you call the stat page or when you use the
cache filter. In fact, this happens when the response is sent by an applet. In
HTTP1, everything seems to work as expected.
To fix the problem, we need to make the difference between the write activity
reported to lower layers and the one reported to the stream. So the flag
CF_WRITE_EVENT has been added to notify the stream of the write activity on a
channel. It is set when a send succedded and reset by process_stream. It is also
used in CF_MASK_ANALYSER. finally, it is checked in stream_int_notify to wake up
a stream and in channel_check_timeouts.
This bug is probably present in 1.7 but it seems to have no effect. So for now,
no needs to backport it.
2017-11-09 03:36:43 -05:00
if ( ! ( req - > flags & ( CF_WRITE_ACTIVITY | CF_WRITE_EVENT ) ) )
2008-11-30 12:47:21 -05:00
return 1 ;
/* OK, this means that a connection succeeded. The caller will be
* responsible for handling the transition from CON to EST .
*/
si - > state = SI_ST_EST ;
si - > err_type = SI_ET_NONE ;
return 1 ;
}
/* This function is called with (si->state == SI_ST_CER) meaning that a
* previous connection attempt has failed and that the file descriptor
* has already been released . Possible causes include asynchronous error
* notification and time out . Possible output states are SI_ST_CLO when
* retries are exhausted , SI_ST_TAR when a delay is wanted before a new
* connection attempt , SI_ST_ASS when it ' s wise to retry on the same server ,
* and SI_ST_REQ when an immediate redispatch is wanted . The buffers are
* marked as in error state . It returns 0.
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static int sess_update_st_cer ( struct stream * s )
2008-11-30 12:47:21 -05:00
{
2014-11-28 09:15:44 -05:00
struct stream_interface * si = & s - > si [ 1 ] ;
2017-09-13 12:30:23 -04:00
struct conn_stream * cs = objt_cs ( si - > end ) ;
struct connection * conn = cs_conn ( cs ) ;
2014-11-28 09:15:44 -05:00
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* we probably have to release last stream from the server */
2012-11-11 18:42:33 -05:00
if ( objt_server ( s - > target ) ) {
health_adjust ( objt_server ( s - > target ) , HANA_STATUS_L4_ERR ) ;
2009-12-15 16:31:24 -05:00
2015-04-02 19:14:29 -04:00
if ( s - > flags & SF_CURR_SESS ) {
s - > flags & = ~ SF_CURR_SESS ;
2017-06-08 08:04:45 -04:00
HA_ATOMIC_SUB ( & objt_server ( s - > target ) - > cur_sess , 1 ) ;
2008-11-30 12:47:21 -05:00
}
2017-07-26 14:13:37 -04:00
if ( ( si - > flags & SI_FL_ERR ) & &
conn & & conn - > err_code = = CO_ER_SSL_MISMATCH_SNI ) {
/* We tried to connect to a server which is configured
* with " verify required " and which doesn ' t have the
* " verifyhost " directive . The server presented a wrong
* certificate ( a certificate for an unexpected name ) ,
* which implies that we have used SNI in the handshake ,
* and that the server doesn ' t have the associated cert
* and presented a default one .
*
* This is a serious enough issue not to retry . It ' s
* especially important because this wrong name might
* either be the result of a configuration error , and
* retrying will only hammer the server , or is caused
* by the use of a wrong SNI value , most likely
* provided by the client and we don ' t want to let the
* client provoke retries .
*/
si - > conn_retries = 0 ;
}
2008-11-30 12:47:21 -05:00
}
/* ensure that we have enough retries left */
2010-06-01 03:51:00 -04:00
si - > conn_retries - - ;
if ( si - > conn_retries < 0 ) {
2008-11-30 12:47:21 -05:00
if ( ! si - > err_type ) {
si - > err_type = SI_ET_CONN_ERR ;
}
2012-11-11 18:42:33 -05:00
if ( objt_server ( s - > target ) )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & objt_server ( s - > target ) - > counters . failed_conns , 1 ) ;
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . failed_conns , 1 ) ;
2010-12-29 08:32:28 -05:00
sess_change_server ( s , NULL ) ;
2012-11-11 18:42:33 -05:00
if ( may_dequeue_tasks ( objt_server ( s - > target ) , s - > be ) )
process_srv_queue ( objt_server ( s - > target ) ) ;
2008-11-30 12:47:21 -05:00
/* shutw is enough so stop a connecting socket */
2012-05-21 10:31:45 -04:00
si_shutw ( si ) ;
2014-11-28 09:26:12 -05:00
s - > req . flags | = CF_WRITE_ERROR ;
s - > res . flags | = CF_READ_ERROR ;
2008-11-30 12:47:21 -05:00
si - > state = SI_ST_CLO ;
2008-11-30 14:44:17 -05:00
if ( s - > srv_error )
s - > srv_error ( s , si ) ;
2008-11-30 12:47:21 -05:00
return 0 ;
}
/* If the "redispatch" option is set on the backend, we are allowed to
2015-05-12 02:25:34 -04:00
* retry on another server . By default this redispatch occurs on the
* last retry , but if configured we allow redispatches to occur on
* configurable intervals , e . g . on every retry . In order to achieve this ,
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* we must mark the stream unassigned , and eventually clear the DIRECT
2008-11-30 12:47:21 -05:00
* bit to ignore any persistence cookie . We won ' t count a retry nor a
* redispatch yet , because this will depend on what server is selected .
2014-06-13 11:49:40 -04:00
* If the connection is not persistent , the balancing algorithm is not
* determinist ( round robin ) and there is more than one active server ,
* we accept to perform an immediate redispatch without waiting since
* we don ' t care about this particular server .
2008-11-30 12:47:21 -05:00
*/
2014-06-13 11:49:40 -04:00
if ( objt_server ( s - > target ) & &
2015-05-12 02:25:34 -04:00
( s - > be - > options & PR_O_REDISP ) & & ! ( s - > flags & SF_FORCE_PRST ) & &
2017-08-31 08:41:55 -04:00
( ( __objt_server ( s - > target ) - > cur_state < SRV_ST_RUNNING ) | |
2016-01-13 01:58:44 -05:00
( ( ( s - > be - > redispatch_after > 0 ) & &
2015-05-12 02:25:34 -04:00
( ( s - > be - > conn_retries - si - > conn_retries ) %
s - > be - > redispatch_after = = 0 ) ) | |
( ( s - > be - > redispatch_after < 0 ) & &
( ( s - > be - > conn_retries - si - > conn_retries ) %
( s - > be - > conn_retries + 1 + s - > be - > redispatch_after ) = = 0 ) ) ) | |
2015-04-02 19:14:29 -04:00
( ! ( s - > flags & SF_DIRECT ) & & s - > be - > srv_act > 1 & &
2015-05-12 02:25:34 -04:00
( ( s - > be - > lbprm . algo & BE_LB_KIND ) = = BE_LB_KIND_RR ) ) ) ) {
2010-12-29 08:32:28 -05:00
sess_change_server ( s , NULL ) ;
2012-11-11 18:42:33 -05:00
if ( may_dequeue_tasks ( objt_server ( s - > target ) , s - > be ) )
process_srv_queue ( objt_server ( s - > target ) ) ;
2008-11-30 12:47:21 -05:00
2015-04-02 19:14:29 -04:00
s - > flags & = ~ ( SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET ) ;
2008-11-30 12:47:21 -05:00
si - > state = SI_ST_REQ ;
} else {
2012-11-11 18:42:33 -05:00
if ( objt_server ( s - > target ) )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & objt_server ( s - > target ) - > counters . retries , 1 ) ;
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . retries , 1 ) ;
2008-11-30 12:47:21 -05:00
si - > state = SI_ST_ASS ;
}
if ( si - > flags & SI_FL_ERR ) {
/* The error was an asynchronous connection error, and we will
* likely have to retry connecting to the same server , most
* likely leading to the same result . To avoid this , we wait
2014-06-13 11:04:44 -04:00
* MIN ( one second , connect timeout ) before retrying .
2008-11-30 12:47:21 -05:00
*/
2014-06-13 11:04:44 -04:00
int delay = 1000 ;
if ( s - > be - > timeout . connect & & s - > be - > timeout . connect < delay )
delay = s - > be - > timeout . connect ;
2008-11-30 12:47:21 -05:00
if ( ! si - > err_type )
si - > err_type = SI_ET_CONN_ERR ;
2014-06-13 11:40:15 -04:00
/* only wait when we're retrying on the same server */
if ( si - > state = = SI_ST_ASS | |
( s - > be - > lbprm . algo & BE_LB_KIND ) ! = BE_LB_KIND_RR | |
( s - > be - > srv_act < = 1 ) ) {
si - > state = SI_ST_TAR ;
si - > exp = tick_add ( now_ms , MS_TO_TICKS ( delay ) ) ;
}
2008-11-30 12:47:21 -05:00
return 0 ;
}
return 0 ;
}
/*
* This function handles the transition between the SI_ST_CON state and the
2010-05-31 05:57:51 -04:00
* SI_ST_EST state . It must only be called after switching from SI_ST_CON ( or
2012-05-07 12:12:14 -04:00
* SI_ST_INI ) to SI_ST_EST , but only when a - > proto is defined .
2008-11-30 12:47:21 -05:00
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static void sess_establish ( struct stream * s )
2008-11-30 12:47:21 -05:00
{
2014-11-28 09:15:44 -05:00
struct stream_interface * si = & s - > si [ 1 ] ;
struct channel * req = & s - > req ;
struct channel * rep = & s - > res ;
2008-11-30 12:47:21 -05:00
2013-12-31 17:06:46 -05:00
/* First, centralize the timers information */
s - > logs . t_connect = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
si - > exp = TICK_ETERNITY ;
2012-11-11 18:42:33 -05:00
if ( objt_server ( s - > target ) )
health_adjust ( objt_server ( s - > target ) , HANA_STATUS_L4_OK ) ;
2009-12-15 16:31:24 -05:00
2008-11-30 12:47:21 -05:00
if ( s - > be - > mode = = PR_MODE_TCP ) { /* let's allow immediate data connection in this case */
/* if the user wants to log as soon as possible, without counting
* bytes from the server , then this is the right moment . */
2015-04-03 20:10:38 -04:00
if ( ! LIST_ISEMPTY ( & strm_fe ( s ) - > logformat ) & & ! ( s - > logs . logwait & LW_BYTES ) ) {
2008-11-30 12:47:21 -05:00
s - > logs . t_close = s - > logs . t_connect ; /* to get a valid end date */
2008-11-30 13:02:32 -05:00
s - > do_log ( s ) ;
2008-11-30 12:47:21 -05:00
}
}
else {
2013-12-31 16:33:13 -05:00
rep - > flags | = CF_READ_DONTWAIT ; /* a single read is enough to get response headers */
2008-11-30 12:47:21 -05:00
}
2016-12-13 09:26:56 -05:00
if ( ! ( s - > flags & SF_TUNNEL ) ) {
rep - > analysers | = strm_fe ( s ) - > fe_rsp_ana | s - > be - > be_rsp_ana ;
2015-12-02 03:57:32 -05:00
2016-12-13 09:26:56 -05:00
/* Be sure to filter response headers if the backend is an HTTP proxy
* and if there are filters attached to the stream . */
if ( s - > be - > mode = = PR_MODE_HTTP & & HAS_FILTERS ( s ) )
rep - > analysers | = AN_RES_FLT_HTTP_HDRS ;
}
2015-12-02 03:57:32 -05:00
2012-08-27 17:14:58 -04:00
rep - > flags | = CF_READ_ATTACHED ; /* producer is now attached */
BUG/MAJOR: http: connection setup may stall on balance url_param
On the mailing list, seri0528@naver.com reported an issue when
using balance url_param or balance uri. The request would sometimes
stall forever.
Cyril Bont managed to reproduce it with the configuration below :
listen test :80
mode http
balance url_param q
hash-type consistent
server s demo.1wt.eu:80
and found it appeared with this commit : 80a92c0 ("BUG/MEDIUM: http:
don't start to forward request data before the connect").
The bug is subtle but real. The problem is that the HTTP request
forwarding analyzer refrains from starting to parse the request
body when some LB algorithms might need the body contents, in order
to preserve the data pointer and avoid moving things around during
analysis in case a redispatch is later needed. And in order to detect
that the connection establishes, it watches the response channel's
CF_READ_ATTACHED flag.
The problem is that a request analyzer is not subscribed to a response
channel, so it will only see changes when woken for other (generally
correlated) reasons, such as the fact that part of the request could
be sent. And since the CF_READ_ATTACHED flag is cleared once leaving
process_session(), it is important not to miss it. It simply happens
that sometimes the server starts to respond in a sequence that validates
the connection in the middle of process_session(), that it is detected
after the analysers, and that the newly assigned CF_READ_ATTACHED is
not used to detect that the request analysers need to be called again,
then the flag is lost.
The CF_WAKE_WRITE flag doesn't work either because it's cleared upon
entry into process_session(), ie if we spend more than one call not
connecting.
Thus we need a new flag to tell the connection initiator that we are
specifically interested in being notified about connection establishment.
This new flag is CF_WAKE_CONNECT. It is set by the requester, and is
cleared once the connection succeeds, where CF_WAKE_ONCE is set instead,
causing the request analysers to be scanned again.
For future versions, some better options will have to be considered :
- let all analysers subscribe to both request and response events ;
- let analysers subscribe to stream interface events (reduces number
of useless calls)
- change CF_WAKE_WRITE's semantics to persist across calls to
process_session(), but that is different from validating a
connection establishment (eg: no data sent, or no data to send)
The bug was introduced in 1.5-dev23, no backport is needed.
2014-04-30 12:11:11 -04:00
if ( req - > flags & CF_WAKE_CONNECT ) {
req - > flags | = CF_WAKE_ONCE ;
req - > flags & = ~ CF_WAKE_CONNECT ;
}
2017-09-13 12:30:23 -04:00
if ( objt_cs ( si - > end ) ) {
2010-05-31 06:31:35 -04:00
/* real connections have timeouts */
req - > wto = s - > be - > timeout . server ;
rep - > rto = s - > be - > timeout . server ;
}
2008-11-30 12:47:21 -05:00
req - > wex = TICK_ETERNITY ;
}
OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.
This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.
sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.
This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 12:01:04 -04:00
/* Check if the connection request is in such a state that it can be aborted. */
static int check_req_may_abort ( struct channel * req , struct stream * s )
{
return ( ( req - > flags & ( CF_READ_ERROR ) ) | |
( ( req - > flags & CF_SHUTW_NOW ) & & /* empty and client aborted */
( channel_is_empty ( req ) | | s - > be - > options & PR_O_ABRT_CLOSE ) ) ) ;
}
2014-11-28 09:15:44 -05:00
/* Update back stream interface status for input states SI_ST_ASS, SI_ST_QUE,
* SI_ST_TAR . Other input states are simply ignored .
2013-12-31 17:32:12 -05:00
* Possible output states are SI_ST_CLO , SI_ST_TAR , SI_ST_ASS , SI_ST_REQ , SI_ST_CON
* and SI_ST_EST . Flags must have previously been updated for timeouts and other
* conditions .
2008-11-30 12:47:21 -05:00
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static void sess_update_stream_int ( struct stream * s )
2008-11-30 12:47:21 -05:00
{
2012-11-11 18:42:33 -05:00
struct server * srv = objt_server ( s - > target ) ;
2014-11-28 09:15:44 -05:00
struct stream_interface * si = & s - > si [ 1 ] ;
2014-11-28 09:26:12 -05:00
struct channel * req = & s - > req ;
2011-03-10 10:55:02 -05:00
2012-03-01 12:19:58 -05:00
DPRINTF ( stderr , " [%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d \n " ,
2008-11-30 12:47:21 -05:00
now_ms , __FUNCTION__ ,
s ,
2015-05-02 16:35:24 -04:00
req , & s - > res ,
2014-11-28 09:26:12 -05:00
req - > rex , s - > res . wex ,
req - > flags , s - > res . flags ,
2015-05-02 16:35:24 -04:00
req - > buf - > i , req - > buf - > o , s - > res . buf - > i , s - > res . buf - > o , s - > si [ 0 ] . state , s - > si [ 1 ] . state ) ;
2008-11-30 12:47:21 -05:00
if ( si - > state = = SI_ST_ASS ) {
/* Server assigned to connection request, we have to try to connect now */
int conn_err ;
OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.
This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.
sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.
This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 12:01:04 -04:00
/* Before we try to initiate the connection, see if the
* request may be aborted instead .
*/
if ( check_req_may_abort ( req , s ) ) {
si - > err_type | = SI_ET_CONN_ABRT ;
goto abort_connection ;
}
2008-11-30 12:47:21 -05:00
conn_err = connect_server ( s ) ;
2012-11-11 18:42:33 -05:00
srv = objt_server ( s - > target ) ;
2011-03-10 10:55:02 -05:00
2015-04-02 19:14:29 -04:00
if ( conn_err = = SF_ERR_NONE ) {
2013-12-31 17:32:12 -05:00
/* state = SI_ST_CON or SI_ST_EST now */
2011-03-10 10:55:02 -05:00
if ( srv )
srv_inc_sess_ctr ( srv ) ;
2014-02-03 16:26:46 -05:00
if ( srv )
srv_set_sess_last ( srv ) ;
2008-11-30 12:47:21 -05:00
return ;
}
/* We have received a synchronous error. We might have to
* abort , retry immediately or redispatch .
*/
2015-04-02 19:14:29 -04:00
if ( conn_err = = SF_ERR_INTERNAL ) {
2008-11-30 12:47:21 -05:00
if ( ! si - > err_type ) {
si - > err_type = SI_ET_CONN_OTHER ;
}
2011-03-10 10:55:02 -05:00
if ( srv )
srv_inc_sess_ctr ( srv ) ;
2014-02-03 16:26:46 -05:00
if ( srv )
srv_set_sess_last ( srv ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . failed_conns , 1 ) ;
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . failed_conns , 1 ) ;
2008-11-30 12:47:21 -05:00
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* release other streams waiting for this server */
2010-12-29 08:32:28 -05:00
sess_change_server ( s , NULL ) ;
2011-03-10 10:55:02 -05:00
if ( may_dequeue_tasks ( srv , s - > be ) )
process_srv_queue ( srv ) ;
2008-11-30 12:47:21 -05:00
/* Failed and not retryable. */
2012-05-21 10:31:45 -04:00
si_shutr ( si ) ;
si_shutw ( si ) ;
2014-11-28 09:26:12 -05:00
req - > flags | = CF_WRITE_ERROR ;
2008-11-30 12:47:21 -05:00
s - > logs . t_queue = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* no stream was ever accounted for this server */
2008-11-30 12:47:21 -05:00
si - > state = SI_ST_CLO ;
2008-11-30 14:44:17 -05:00
if ( s - > srv_error )
s - > srv_error ( s , si ) ;
2008-11-30 12:47:21 -05:00
return ;
}
/* We are facing a retryable error, but we don't want to run a
* turn - around now , as the problem is likely a source port
* allocation problem , so we want to retry now .
*/
si - > state = SI_ST_CER ;
si - > flags & = ~ SI_FL_ERR ;
2014-11-28 09:15:44 -05:00
sess_update_st_cer ( s ) ;
2008-11-30 12:47:21 -05:00
/* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */
return ;
}
else if ( si - > state = = SI_ST_QUE ) {
/* connection request was queued, check for any update */
if ( ! s - > pend_pos ) {
/* The connection is not in the queue anymore. Either
* we have a server connection slot available and we
* go directly to the assigned state , or we need to
* load - balance first and go to the INI state .
*/
si - > exp = TICK_ETERNITY ;
2015-04-02 19:14:29 -04:00
if ( unlikely ( ! ( s - > flags & SF_ASSIGNED ) ) )
2008-11-30 12:47:21 -05:00
si - > state = SI_ST_REQ ;
else {
s - > logs . t_queue = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
si - > state = SI_ST_ASS ;
}
return ;
}
/* Connection request still in queue... */
if ( si - > flags & SI_FL_EXP ) {
/* ... and timeout expired */
si - > exp = TICK_ETERNITY ;
s - > logs . t_queue = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . failed_conns , 1 ) ;
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . failed_conns , 1 ) ;
2012-05-21 10:31:45 -04:00
si_shutr ( si ) ;
si_shutw ( si ) ;
2014-11-28 09:26:12 -05:00
req - > flags | = CF_WRITE_TIMEOUT ;
2008-11-30 12:47:21 -05:00
if ( ! si - > err_type )
si - > err_type = SI_ET_QUEUE_TO ;
si - > state = SI_ST_CLO ;
2008-11-30 14:44:17 -05:00
if ( s - > srv_error )
s - > srv_error ( s , si ) ;
2008-11-30 12:47:21 -05:00
return ;
}
/* Connection remains in queue, check if we have to abort it */
OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.
This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.
sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.
This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 12:01:04 -04:00
if ( check_req_may_abort ( req , s ) ) {
2008-11-30 12:47:21 -05:00
s - > logs . t_queue = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
si - > err_type | = SI_ET_QUEUE_ABRT ;
OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.
This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.
sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.
This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 12:01:04 -04:00
goto abort_connection ;
2008-11-30 12:47:21 -05:00
}
/* Nothing changed */
return ;
}
else if ( si - > state = = SI_ST_TAR ) {
/* Connection request might be aborted */
OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.
This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.
sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.
This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 12:01:04 -04:00
if ( check_req_may_abort ( req , s ) ) {
2008-11-30 12:47:21 -05:00
si - > err_type | = SI_ET_CONN_ABRT ;
OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.
This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.
sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.
This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 12:01:04 -04:00
goto abort_connection ;
2008-11-30 12:47:21 -05:00
}
if ( ! ( si - > flags & SI_FL_EXP ) )
return ; /* still in turn-around */
si - > exp = TICK_ETERNITY ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* we keep trying on the same server as long as the stream is
2008-11-30 12:47:21 -05:00
* marked " assigned " .
* FIXME : Should we force a redispatch attempt when the server is down ?
*/
2015-04-02 19:14:29 -04:00
if ( s - > flags & SF_ASSIGNED )
2008-11-30 12:47:21 -05:00
si - > state = SI_ST_ASS ;
else
si - > state = SI_ST_REQ ;
return ;
}
OPTIM/MINOR: session: abort if possible before connecting to the backend
Depending on the path that led to sess_update_stream_int(), it's
possible that we had a read error on the frontend, but that we haven't
checked if we may abort the connection.
This was seen in particular the following setup: tcp mode, with
abortonclose set, frontend using ssl. If the ssl connection had a first
successful read, but the second read failed, we would stil try to open a
connection to the backend, although we had enough information to close
the connection early.
sess_update_stream_int() had some logic to handle that case in the
SI_ST_QUE and SI_ST_TAR, but that was missing in the SI_ST_ASS case.
This patches addresses the issue by verifying the state of the req
channel (and the abortonclose option) right before opening the
connection to the backend, so we have the opportunity to close the
connection there, and factorizes the shared SI_ST_{QUE,TAR,ASS} code.
2016-04-07 12:01:04 -04:00
return ;
abort_connection :
/* give up */
si - > exp = TICK_ETERNITY ;
si_shutr ( si ) ;
si_shutw ( si ) ;
si - > state = SI_ST_CLO ;
if ( s - > srv_error )
s - > srv_error ( s , si ) ;
return ;
2008-11-30 12:47:21 -05:00
}
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* Set correct stream termination flags in case no analyser has done it. It
2011-06-07 20:19:07 -04:00
* also counts a failed request if the server state has not reached the request
* stage .
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static void sess_set_term_flags ( struct stream * s )
2011-06-07 20:19:07 -04:00
{
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_FINST_MASK ) ) {
2011-06-07 20:19:07 -04:00
if ( s - > si [ 1 ] . state < SI_ST_REQ ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & strm_fe ( s ) - > fe_counters . failed_req , 1 ) ;
2015-09-23 06:21:21 -04:00
if ( strm_li ( s ) & & strm_li ( s ) - > counters )
2017-05-30 09:36:50 -04:00
HA_ATOMIC_ADD ( & strm_li ( s ) - > counters - > failed_req , 1 ) ;
2011-06-07 20:19:07 -04:00
2015-04-02 19:14:29 -04:00
s - > flags | = SF_FINST_R ;
2011-06-07 20:19:07 -04:00
}
else if ( s - > si [ 1 ] . state = = SI_ST_QUE )
2015-04-02 19:14:29 -04:00
s - > flags | = SF_FINST_Q ;
2011-06-07 20:19:07 -04:00
else if ( s - > si [ 1 ] . state < SI_ST_EST )
2015-04-02 19:14:29 -04:00
s - > flags | = SF_FINST_C ;
2011-06-07 20:19:07 -04:00
else if ( s - > si [ 1 ] . state = = SI_ST_EST | | s - > si [ 1 ] . prev_state = = SI_ST_EST )
2015-04-02 19:14:29 -04:00
s - > flags | = SF_FINST_D ;
2011-06-07 20:19:07 -04:00
else
2015-04-02 19:14:29 -04:00
s - > flags | = SF_FINST_L ;
2011-06-07 20:19:07 -04:00
}
}
2008-11-30 12:47:21 -05:00
/* This function initiates a server connection request on a stream interface
2013-11-30 03:06:53 -05:00
* already in SI_ST_REQ state . Upon success , the state goes to SI_ST_ASS for
* a real connection to a server , indicating that a server has been assigned ,
* or SI_ST_EST for a successful connection to an applet . It may also return
* SI_ST_QUE , or SI_ST_CLO upon error .
2008-11-30 12:47:21 -05:00
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static void sess_prepare_conn_req ( struct stream * s )
2012-03-01 12:19:58 -05:00
{
2014-11-28 09:15:44 -05:00
struct stream_interface * si = & s - > si [ 1 ] ;
2012-03-01 12:19:58 -05:00
DPRINTF ( stderr , " [%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d \n " ,
2008-11-30 12:47:21 -05:00
now_ms , __FUNCTION__ ,
s ,
2015-05-02 16:35:24 -04:00
& s - > req , & s - > res ,
2014-11-27 14:45:39 -05:00
s - > req . rex , s - > res . wex ,
s - > req . flags , s - > res . flags ,
2015-05-02 16:35:24 -04:00
s - > req . buf - > i , s - > req . buf - > o , s - > res . buf - > i , s - > res . buf - > o , s - > si [ 0 ] . state , s - > si [ 1 ] . state ) ;
2008-11-30 12:47:21 -05:00
if ( si - > state ! = SI_ST_REQ )
return ;
2013-11-30 03:06:53 -05:00
if ( unlikely ( obj_type ( s - > target ) = = OBJ_TYPE_APPLET ) ) {
/* the applet directly goes to the EST state */
2013-12-01 06:25:52 -05:00
struct appctx * appctx = objt_appctx ( si - > end ) ;
if ( ! appctx | | appctx - > applet ! = __objt_applet ( s - > target ) )
appctx = stream_int_register_handler ( si , objt_applet ( s - > target ) ) ;
if ( ! appctx ) {
/* No more memory, let's immediately abort. Force the
* error code to ignore the ERR_LOCAL which is not a
* real error .
*/
2015-04-02 19:14:29 -04:00
s - > flags & = ~ ( SF_ERR_MASK | SF_FINST_MASK ) ;
2013-12-01 06:25:52 -05:00
si_shutr ( si ) ;
si_shutw ( si ) ;
2014-11-28 09:26:12 -05:00
s - > req . flags | = CF_WRITE_ERROR ;
2013-12-09 11:14:23 -05:00
si - > err_type = SI_ET_CONN_RES ;
2013-12-01 06:25:52 -05:00
si - > state = SI_ST_CLO ;
if ( s - > srv_error )
s - > srv_error ( s , si ) ;
return ;
}
2013-11-30 03:06:53 -05:00
s - > logs . t_queue = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
si - > state = SI_ST_EST ;
si - > err_type = SI_ET_NONE ;
2014-04-22 18:35:17 -04:00
be_set_sess_last ( s - > be ) ;
2013-11-30 03:21:49 -05:00
/* let sess_establish() finish the job */
2013-11-30 03:06:53 -05:00
return ;
}
2008-11-30 12:47:21 -05:00
/* Try to assign a server */
if ( srv_redispatch_connect ( s ) ! = 0 ) {
/* We did not get a server. Either we queued the
* connection request , or we encountered an error .
*/
if ( si - > state = = SI_ST_QUE )
return ;
/* we did not get any server, let's check the cause */
2012-05-21 10:31:45 -04:00
si_shutr ( si ) ;
si_shutw ( si ) ;
2014-11-28 09:26:12 -05:00
s - > req . flags | = CF_WRITE_ERROR ;
2008-11-30 12:47:21 -05:00
if ( ! si - > err_type )
si - > err_type = SI_ET_CONN_OTHER ;
si - > state = SI_ST_CLO ;
2008-11-30 14:44:17 -05:00
if ( s - > srv_error )
s - > srv_error ( s , si ) ;
2008-11-30 12:47:21 -05:00
return ;
}
/* The server is assigned */
s - > logs . t_queue = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
si - > state = SI_ST_ASS ;
2014-04-22 18:35:17 -04:00
be_set_sess_last ( s - > be ) ;
2008-11-30 12:47:21 -05:00
}
2015-09-27 13:29:33 -04:00
/* This function parses the use-service action ruleset. It executes
* the associated ACL and set an applet as a stream or txn final node .
* it returns ACT_RET_ERR if an error occurs , the proxy left in
* consistent state . It returns ACT_RET_STOP in succes case because
* use - service must be a terminal action . Returns ACT_RET_YIELD
* if the initialisation function require more data .
*/
enum act_return process_use_service ( struct act_rule * rule , struct proxy * px ,
struct session * sess , struct stream * s , int flags )
{
struct appctx * appctx ;
/* Initialises the applet if it is required. */
if ( flags & ACT_FLAG_FIRST ) {
/* Register applet. this function schedules the applet. */
s - > target = & rule - > applet . obj_type ;
if ( unlikely ( ! stream_int_register_handler ( & s - > si [ 1 ] , objt_applet ( s - > target ) ) ) )
return ACT_RET_ERR ;
/* Initialise the context. */
appctx = si_appctx ( & s - > si [ 1 ] ) ;
memset ( & appctx - > ctx , 0 , sizeof ( appctx - > ctx ) ) ;
appctx - > rule = rule ;
2017-08-23 04:52:20 -04:00
/* enable the minimally required analyzers in case of HTTP
* keep - alive to properly handle keep - alive and compression
* on the HTTP response .
*/
if ( rule - > from = = ACT_F_HTTP_REQ ) {
s - > req . analysers & = AN_REQ_FLT_HTTP_HDRS | AN_REQ_FLT_END ;
s - > req . analysers | = AN_REQ_HTTP_XFER_BODY ;
}
2015-09-27 13:29:33 -04:00
}
else
appctx = si_appctx ( & s - > si [ 1 ] ) ;
/* Stops the applet sheduling, in case of the init function miss
* some data .
*/
si_applet_stop_get ( & s - > si [ 1 ] ) ;
/* Call initialisation. */
if ( rule - > applet . init )
switch ( rule - > applet . init ( appctx , px , s ) ) {
case 0 : return ACT_RET_ERR ;
case 1 : break ;
default : return ACT_RET_YIELD ;
}
/* Now we can schedule the applet. */
si_applet_cant_get ( & s - > si [ 1 ] ) ;
appctx_wakeup ( appctx ) ;
if ( sess - > fe = = s - > be ) /* report it if the request was intercepted by the frontend */
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . intercepted_req , 1 ) ;
2015-09-27 13:29:33 -04:00
/* The flag SF_ASSIGNED prevent from server assignment. */
s - > flags | = SF_ASSIGNED ;
return ACT_RET_STOP ;
}
2009-07-07 09:10:31 -04:00
/* This stream analyser checks the switching rules and changes the backend
2010-01-22 13:10:05 -05:00
* if appropriate . The default_backend rule is also considered , then the
* target backend ' s forced persistence rules are also evaluated last if any .
2009-07-07 09:10:31 -04:00
* It returns 1 if the processing can continue on next analysers , or zero if it
* either needs more data or wants to immediately abort the request .
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static int process_switching_rules ( struct stream * s , struct channel * req , int an_bit )
2009-07-07 09:10:31 -04:00
{
2010-04-24 18:00:51 -04:00
struct persist_rule * prst_rule ;
2015-04-03 19:47:55 -04:00
struct session * sess = s - > sess ;
struct proxy * fe = sess - > fe ;
2010-01-22 13:10:05 -05:00
2009-07-07 09:10:31 -04:00
req - > analysers & = ~ an_bit ;
req - > analyse_exp = TICK_ETERNITY ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
DPRINTF ( stderr , " [%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x \n " ,
2009-07-07 09:10:31 -04:00
now_ms , __FUNCTION__ ,
s ,
req ,
req - > rex , req - > wex ,
req - > flags ,
2012-10-12 17:49:43 -04:00
req - > buf - > i ,
2009-07-07 09:10:31 -04:00
req - > analysers ) ;
/* now check whether we have some switching rules for this request */
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_BE_ASSIGNED ) ) {
2009-07-07 09:10:31 -04:00
struct switching_rule * rule ;
2015-04-03 09:40:56 -04:00
list_for_each_entry ( rule , & fe - > switching_rules , list ) {
2014-04-22 19:21:56 -04:00
int ret = 1 ;
2009-07-07 09:10:31 -04:00
2014-04-22 19:21:56 -04:00
if ( rule - > cond ) {
2015-04-03 19:47:55 -04:00
ret = acl_exec_cond ( rule - > cond , fe , sess , s , SMP_OPT_DIR_REQ | SMP_OPT_FINAL ) ;
2014-04-22 19:21:56 -04:00
ret = acl_pass ( ret ) ;
if ( rule - > cond - > pol = = ACL_COND_UNLESS )
ret = ! ret ;
}
2009-07-07 09:10:31 -04:00
if ( ret ) {
2013-11-19 05:43:06 -05:00
/* If the backend name is dynamic, try to resolve the name.
* If we can ' t resolve the name , or if any error occurs , break
* the loop and fallback to the default backend .
*/
2017-10-26 05:25:10 -04:00
struct proxy * backend = NULL ;
2013-11-19 05:43:06 -05:00
if ( rule - > dynamic ) {
2017-10-26 05:25:10 -04:00
struct chunk * tmp ;
tmp = alloc_trash_chunk ( ) ;
if ( ! tmp )
goto sw_failed ;
if ( build_logline ( s , tmp - > str , tmp - > size , & rule - > be . expr ) )
backend = proxy_be_by_name ( tmp - > str ) ;
free_trash_chunk ( tmp ) ;
tmp = NULL ;
2013-11-19 05:43:06 -05:00
if ( ! backend )
break ;
}
else
backend = rule - > be . backend ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
if ( ! stream_set_backend ( s , backend ) )
2009-07-12 02:27:39 -04:00
goto sw_failed ;
2009-07-07 09:10:31 -04:00
break ;
}
}
/* To ensure correct connection accounting on the backend, we
* have to assign one if it was not set ( eg : a listen ) . This
* measure also takes care of correctly setting the default
* backend if any .
*/
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_BE_ASSIGNED ) )
2015-04-03 09:40:56 -04:00
if ( ! stream_set_backend ( s , fe - > defbe . be ? fe - > defbe . be : s - > be ) )
2009-07-12 02:27:39 -04:00
goto sw_failed ;
2009-07-07 09:10:31 -04:00
}
2010-08-03 08:02:05 -04:00
/* we don't want to run the TCP or HTTP filters again if the backend has not changed */
2015-04-03 09:40:56 -04:00
if ( fe = = s - > be ) {
2014-11-27 14:45:39 -05:00
s - > req . analysers & = ~ AN_REQ_INSPECT_BE ;
s - > req . analysers & = ~ AN_REQ_HTTP_PROCESS_BE ;
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
s - > req . analysers & = ~ AN_REQ_FLT_START_BE ;
2010-08-03 08:02:05 -04:00
}
2009-07-07 09:10:31 -04:00
2010-04-24 18:00:51 -04:00
/* as soon as we know the backend, we must check if we have a matching forced or ignored
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* persistence rule , and report that in the stream .
2010-01-22 13:10:05 -05:00
*/
2010-04-24 18:00:51 -04:00
list_for_each_entry ( prst_rule , & s - > be - > persist_rules , list ) {
2010-01-22 13:10:05 -05:00
int ret = 1 ;
if ( prst_rule - > cond ) {
2015-04-03 19:47:55 -04:00
ret = acl_exec_cond ( prst_rule - > cond , s - > be , sess , s , SMP_OPT_DIR_REQ | SMP_OPT_FINAL ) ;
2010-01-22 13:10:05 -05:00
ret = acl_pass ( ret ) ;
if ( prst_rule - > cond - > pol = = ACL_COND_UNLESS )
ret = ! ret ;
}
if ( ret ) {
/* no rule, or the rule matches */
2010-04-24 18:00:51 -04:00
if ( prst_rule - > type = = PERSIST_TYPE_FORCE ) {
2015-04-02 19:14:29 -04:00
s - > flags | = SF_FORCE_PRST ;
2010-04-24 18:00:51 -04:00
} else {
2015-04-02 19:14:29 -04:00
s - > flags | = SF_IGNORE_PRST ;
2010-04-24 18:00:51 -04:00
}
2010-01-22 13:10:05 -05:00
break ;
}
}
2009-07-07 09:10:31 -04:00
return 1 ;
2009-07-12 02:27:39 -04:00
sw_failed :
/* immediately abort this request in case of allocation failure */
2014-11-27 14:45:39 -05:00
channel_abort ( & s - > req ) ;
channel_abort ( & s - > res ) ;
2009-07-12 02:27:39 -04:00
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_ERR_MASK ) )
s - > flags | = SF_ERR_RESOURCE ;
if ( ! ( s - > flags & SF_FINST_MASK ) )
s - > flags | = SF_FINST_R ;
2009-07-12 02:27:39 -04:00
2015-04-03 17:46:31 -04:00
if ( s - > txn )
s - > txn - > status = 500 ;
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
s - > req . analysers & = AN_REQ_FLT_END ;
2014-11-27 14:45:39 -05:00
s - > req . analyse_exp = TICK_ETERNITY ;
2009-07-12 02:27:39 -04:00
return 0 ;
2009-07-07 09:10:31 -04:00
}
2012-04-05 15:09:48 -04:00
/* This stream analyser works on a request. It applies all use-server rules on
* it then returns 1. The data must already be present in the buffer otherwise
* they won ' t match . It always returns 1.
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static int process_server_rules ( struct stream * s , struct channel * req , int an_bit )
2012-04-05 15:09:48 -04:00
{
struct proxy * px = s - > be ;
2015-04-03 19:47:55 -04:00
struct session * sess = s - > sess ;
2012-04-05 15:09:48 -04:00
struct server_rule * rule ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
DPRINTF ( stderr , " [%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x \n " ,
2012-04-05 15:09:48 -04:00
now_ms , __FUNCTION__ ,
s ,
req ,
req - > rex , req - > wex ,
req - > flags ,
2012-10-12 17:49:43 -04:00
req - > buf - > i + req - > buf - > o ,
2012-04-05 15:09:48 -04:00
req - > analysers ) ;
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_ASSIGNED ) ) {
2012-04-05 15:09:48 -04:00
list_for_each_entry ( rule , & px - > server_rules , list ) {
int ret ;
2015-04-03 19:47:55 -04:00
ret = acl_exec_cond ( rule - > cond , s - > be , sess , s , SMP_OPT_DIR_REQ | SMP_OPT_FINAL ) ;
2012-04-05 15:09:48 -04:00
ret = acl_pass ( ret ) ;
if ( rule - > cond - > pol = = ACL_COND_UNLESS )
ret = ! ret ;
if ( ret ) {
struct server * srv = rule - > srv . ptr ;
2017-08-31 08:41:55 -04:00
if ( ( srv - > cur_state ! = SRV_ST_STOPPED ) | |
2012-04-05 15:09:48 -04:00
( px - > options & PR_O_PERSIST ) | |
2015-04-02 19:14:29 -04:00
( s - > flags & SF_FORCE_PRST ) ) {
s - > flags | = SF_DIRECT | SF_ASSIGNED ;
2012-11-11 18:42:33 -05:00
s - > target = & srv - > obj_type ;
2012-04-05 15:09:48 -04:00
break ;
}
/* if the server is not UP, let's go on with next rules
* just in case another one is suited .
*/
}
}
}
req - > analysers & = ~ an_bit ;
req - > analyse_exp = TICK_ETERNITY ;
return 1 ;
}
2010-01-04 09:47:17 -05:00
/* This stream analyser works on a request. It applies all sticking rules on
* it then returns 1. The data must already be present in the buffer otherwise
* they won ' t match . It always returns 1.
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static int process_sticking_rules ( struct stream * s , struct channel * req , int an_bit )
2010-01-04 09:47:17 -05:00
{
struct proxy * px = s - > be ;
2015-04-03 19:47:55 -04:00
struct session * sess = s - > sess ;
2010-01-04 09:47:17 -05:00
struct sticking_rule * rule ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
DPRINTF ( stderr , " [%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x \n " ,
2010-01-04 09:47:17 -05:00
now_ms , __FUNCTION__ ,
s ,
req ,
req - > rex , req - > wex ,
req - > flags ,
2012-10-12 17:49:43 -04:00
req - > buf - > i ,
2010-01-04 09:47:17 -05:00
req - > analysers ) ;
list_for_each_entry ( rule , & px - > sticking_rules , list ) {
int ret = 1 ;
int i ;
2013-12-09 06:52:13 -05:00
/* Only the first stick store-request of each table is applied
* and other ones are ignored . The purpose is to allow complex
* configurations which look for multiple entries by decreasing
* order of precision and to stop at the first which matches .
* An example could be a store of the IP address from an HTTP
* header first , then from the source if not found .
*/
2010-01-04 09:47:17 -05:00
for ( i = 0 ; i < s - > store_count ; i + + ) {
if ( rule - > table . t = = s - > store [ i ] . table )
break ;
}
if ( i ! = s - > store_count )
continue ;
if ( rule - > cond ) {
2015-04-03 19:47:55 -04:00
ret = acl_exec_cond ( rule - > cond , px , sess , s , SMP_OPT_DIR_REQ | SMP_OPT_FINAL ) ;
2010-01-04 09:47:17 -05:00
ret = acl_pass ( ret ) ;
if ( rule - > cond - > pol = = ACL_COND_UNLESS )
ret = ! ret ;
}
if ( ret ) {
struct stktable_key * key ;
2015-04-03 19:47:55 -04:00
key = stktable_fetch_key ( rule - > table . t , px , sess , s , SMP_OPT_DIR_REQ | SMP_OPT_FINAL , rule - > expr , NULL ) ;
2010-01-04 09:47:17 -05:00
if ( ! key )
continue ;
if ( rule - > flags & STK_IS_MATCH ) {
struct stksess * ts ;
2010-06-06 09:38:59 -04:00
if ( ( ts = stktable_lookup_key ( rule - > table . t , key ) ) ! = NULL ) {
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_ASSIGNED ) ) {
2010-01-04 09:47:17 -05:00
struct eb32_node * node ;
2010-06-06 10:40:39 -04:00
void * ptr ;
2010-01-04 09:47:17 -05:00
/* srv found in table */
2017-11-07 04:42:54 -05:00
HA_RWLOCK_RDLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2010-06-06 10:40:39 -04:00
ptr = stktable_data_ptr ( rule - > table . t , ts , STKTABLE_DT_SERVER_ID ) ;
node = eb32_lookup ( & px - > conf . used_server_id , stktable_data_cast ( ptr , server_id ) ) ;
2017-11-07 04:42:54 -05:00
HA_RWLOCK_RDUNLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2010-01-04 09:47:17 -05:00
if ( node ) {
struct server * srv ;
srv = container_of ( node , struct server , conf . id ) ;
2017-08-31 08:41:55 -04:00
if ( ( srv - > cur_state ! = SRV_ST_STOPPED ) | |
2010-01-22 13:10:05 -05:00
( px - > options & PR_O_PERSIST ) | |
2015-04-02 19:14:29 -04:00
( s - > flags & SF_FORCE_PRST ) ) {
s - > flags | = SF_DIRECT | SF_ASSIGNED ;
2012-11-11 18:42:33 -05:00
s - > target = & srv - > obj_type ;
2010-01-04 09:47:17 -05:00
}
}
}
2017-06-13 13:37:32 -04:00
stktable_touch_local ( rule - > table . t , ts , 1 ) ;
2010-01-04 09:47:17 -05:00
}
}
if ( rule - > flags & STK_IS_STORE ) {
if ( s - > store_count < ( sizeof ( s - > store ) / sizeof ( s - > store [ 0 ] ) ) ) {
struct stksess * ts ;
ts = stksess_new ( rule - > table . t , key ) ;
if ( ts ) {
s - > store [ s - > store_count ] . table = rule - > table . t ;
s - > store [ s - > store_count + + ] . ts = ts ;
}
}
}
}
}
req - > analysers & = ~ an_bit ;
req - > analyse_exp = TICK_ETERNITY ;
return 1 ;
}
/* This stream analyser works on a response. It applies all store rules on it
* then returns 1. The data must already be present in the buffer otherwise
* they won ' t match . It always returns 1.
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static int process_store_rules ( struct stream * s , struct channel * rep , int an_bit )
2010-01-04 09:47:17 -05:00
{
struct proxy * px = s - > be ;
2015-04-03 19:47:55 -04:00
struct session * sess = s - > sess ;
2010-01-04 09:47:17 -05:00
struct sticking_rule * rule ;
int i ;
2013-12-09 06:52:13 -05:00
int nbreq = s - > store_count ;
2010-01-04 09:47:17 -05:00
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
DPRINTF ( stderr , " [%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x \n " ,
2010-01-04 09:47:17 -05:00
now_ms , __FUNCTION__ ,
s ,
2010-02-09 14:55:44 -05:00
rep ,
rep - > rex , rep - > wex ,
rep - > flags ,
2012-10-12 17:49:43 -04:00
rep - > buf - > i ,
2010-02-09 14:55:44 -05:00
rep - > analysers ) ;
2010-01-04 09:47:17 -05:00
list_for_each_entry ( rule , & px - > storersp_rules , list ) {
int ret = 1 ;
2013-12-09 06:52:13 -05:00
/* Only the first stick store-response of each table is applied
* and other ones are ignored . The purpose is to allow complex
* configurations which look for multiple entries by decreasing
* order of precision and to stop at the first which matches .
* An example could be a store of a set - cookie value , with a
* fallback to a parameter found in a 302 redirect .
*
* The store - response rules are not allowed to override the
* store - request rules for the same table , but they may coexist .
* Thus we can have up to one store - request entry and one store -
* response entry for the same table at any time .
*/
for ( i = nbreq ; i < s - > store_count ; i + + ) {
if ( rule - > table . t = = s - > store [ i ] . table )
break ;
}
/* skip existing entries for this table */
if ( i < s - > store_count )
continue ;
2010-01-04 09:47:17 -05:00
if ( rule - > cond ) {
2015-04-03 19:47:55 -04:00
ret = acl_exec_cond ( rule - > cond , px , sess , s , SMP_OPT_DIR_RES | SMP_OPT_FINAL ) ;
2010-01-04 09:47:17 -05:00
ret = acl_pass ( ret ) ;
if ( rule - > cond - > pol = = ACL_COND_UNLESS )
ret = ! ret ;
}
if ( ret ) {
struct stktable_key * key ;
2015-04-03 19:47:55 -04:00
key = stktable_fetch_key ( rule - > table . t , px , sess , s , SMP_OPT_DIR_RES | SMP_OPT_FINAL , rule - > expr , NULL ) ;
2010-01-04 09:47:17 -05:00
if ( ! key )
continue ;
BUG/MEDIUM: stick: completely remove the unused flag from the store entries
The store[] array in the session holds a flag which probably aimed to
differenciate store entries learned from the request from those learned
from the response, and allowing responses to overwrite only the request
ones (eg: have a server set a response cookie which overwrites the request
one).
But this flag is set when a response data is stored, and is never cleared.
So in practice, haproxy always runs with this flag set, meaning that
responses prevent themselves from overriding the request data.
It is desirable anyway to keep the ability not to override data, because
the override is performed only based on the table and not on the key, so
that would mean that it would be impossible to retrieve two different
keys to store into a same table. For example, if a client sets a cookie
and a server another one, both need to be updated in the table in the
proper order. This is especially true when multiple keys may be tracked
on each side into the same table (eg: list of IP addresses in a header).
So the correct fix which also maintains the current behaviour consists in
simply removing this flag and never try to optimize for the overwrite case.
This fix also has the benefit of significantly reducing the session size,
by 64 bytes due to alignment issues caused by this flag!
The bug has been there forever (since 1.4-dev7), so a backport to 1.4
would be appropriate.
2013-12-06 17:05:21 -05:00
if ( s - > store_count < ( sizeof ( s - > store ) / sizeof ( s - > store [ 0 ] ) ) ) {
2010-01-04 09:47:17 -05:00
struct stksess * ts ;
ts = stksess_new ( rule - > table . t , key ) ;
if ( ts ) {
s - > store [ s - > store_count ] . table = rule - > table . t ;
s - > store [ s - > store_count + + ] . ts = ts ;
}
}
}
}
/* process store request and store response */
for ( i = 0 ; i < s - > store_count ; i + + ) {
2010-06-06 09:38:59 -04:00
struct stksess * ts ;
2010-06-06 10:40:39 -04:00
void * ptr ;
2010-06-06 09:38:59 -04:00
2014-05-13 09:54:22 -04:00
if ( objt_server ( s - > target ) & & objt_server ( s - > target ) - > flags & SRV_F_NON_STICK ) {
2011-06-24 20:39:49 -04:00
stksess_free ( s - > store [ i ] . table , s - > store [ i ] . ts ) ;
s - > store [ i ] . ts = NULL ;
continue ;
}
2017-06-13 13:37:32 -04:00
ts = stktable_set_entry ( s - > store [ i ] . table , s - > store [ i ] . ts ) ;
if ( ts ! = s - > store [ i ] . ts ) {
2010-06-06 09:38:59 -04:00
/* the entry already existed, we can free ours */
2010-01-04 09:47:17 -05:00
stksess_free ( s - > store [ i ] . table , s - > store [ i ] . ts ) ;
}
2010-06-06 09:38:59 -04:00
s - > store [ i ] . ts = NULL ;
2017-06-13 13:37:32 -04:00
2017-11-07 04:42:54 -05:00
HA_RWLOCK_WRLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2010-06-06 10:40:39 -04:00
ptr = stktable_data_ptr ( s - > store [ i ] . table , ts , STKTABLE_DT_SERVER_ID ) ;
2012-11-11 18:42:33 -05:00
stktable_data_cast ( ptr , server_id ) = objt_server ( s - > target ) - > puid ;
2017-11-07 04:42:54 -05:00
HA_RWLOCK_WRUNLOCK ( STK_SESS_LOCK , & ts - > lock ) ;
2017-06-13 13:37:32 -04:00
stktable_touch_local ( s - > store [ i ] . table , ts , 1 ) ;
2010-01-04 09:47:17 -05:00
}
2010-06-18 03:57:45 -04:00
s - > store_count = 0 ; /* everything is stored */
2010-01-04 09:47:17 -05:00
rep - > analysers & = ~ an_bit ;
rep - > analyse_exp = TICK_ETERNITY ;
return 1 ;
}
2010-01-06 17:53:24 -05:00
/* This macro is very specific to the function below. See the comments in
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* process_stream ( ) below to understand the logic and the tests .
2010-01-06 17:53:24 -05:00
*/
# define UPDATE_ANALYSERS(real, list, back, flag) { \
list = ( ( ( list ) & ~ ( flag ) ) | ~ ( back ) ) & ( real ) ; \
back = real ; \
if ( ! ( list ) ) \
break ; \
if ( ( ( list ) ^ ( ( list ) & ( ( list ) - 1 ) ) ) < ( flag ) ) \
continue ; \
}
2016-05-11 11:06:28 -04:00
/* These 2 following macros call an analayzer for the specified channel if the
* right flag is set . The first one is used for " filterable " analyzers . If a
2016-05-11 11:13:39 -04:00
* stream has some registered filters , pre and post analyaze callbacks are
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
* called . The second are used for other analyzers ( AN_REQ / RES_FLT_ * and
2016-05-11 11:06:28 -04:00
* AN_REQ / RES_HTTP_XFER_BODY ) */
# define FLT_ANALYZE(strm, chn, fun, list, back, flag, ...) \
{ \
if ( ( list ) & ( flag ) ) { \
if ( HAS_FILTERS ( strm ) ) { \
2016-05-11 11:13:39 -04:00
if ( ! flt_pre_analyze ( ( strm ) , ( chn ) , ( flag ) ) ) \
2016-05-11 11:06:28 -04:00
break ; \
if ( ! fun ( ( strm ) , ( chn ) , ( flag ) , # # __VA_ARGS__ ) ) \
break ; \
2016-05-11 11:13:39 -04:00
if ( ! flt_post_analyze ( ( strm ) , ( chn ) , ( flag ) ) ) \
break ; \
2016-05-11 11:06:28 -04:00
} \
else { \
if ( ! fun ( ( strm ) , ( chn ) , ( flag ) , # # __VA_ARGS__ ) ) \
break ; \
} \
UPDATE_ANALYSERS ( ( chn ) - > analysers , ( list ) , \
( back ) , ( flag ) ) ; \
} \
}
# define ANALYZE(strm, chn, fun, list, back, flag, ...) \
{ \
if ( ( list ) & ( flag ) ) { \
if ( ! fun ( ( strm ) , ( chn ) , ( flag ) , # # __VA_ARGS__ ) ) \
break ; \
UPDATE_ANALYSERS ( ( chn ) - > analysers , ( list ) , \
( back ) , ( flag ) ) ; \
} \
}
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* Processes the client, server, request and response jobs of a stream task,
2008-11-30 12:47:21 -05:00
* then puts it back to the wait queue in a clean state , or cleans up its
* resources if it must be deleted . Returns in < next > the date the task wants
* to be woken up , or TICK_ETERNITY . In order not to call all functions for
* nothing too many times , the request and response buffers flags are monitored
* and each function is called only if at least another function has changed at
* least one flag it is interested in .
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
struct task * process_stream ( struct task * t )
2008-11-30 12:47:21 -05:00
{
2011-03-10 10:55:02 -05:00
struct server * srv ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
struct stream * s = t - > context ;
2015-04-03 08:46:27 -04:00
struct session * sess = s - > sess ;
2008-11-30 12:47:21 -05:00
unsigned int rqf_last , rpf_last ;
2010-07-27 11:15:12 -04:00
unsigned int rq_prod_last , rq_cons_last ;
unsigned int rp_cons_last , rp_prod_last ;
2010-01-06 18:09:04 -05:00
unsigned int req_ana_back ;
2014-11-28 09:07:47 -05:00
struct channel * req , * res ;
struct stream_interface * si_f , * si_b ;
req = & s - > req ;
res = & s - > res ;
si_f = & s - > si [ 0 ] ;
si_b = & s - > si [ 1 ] ;
2008-11-30 12:47:21 -05:00
//DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__,
2014-11-28 09:07:47 -05:00
// si_f->state, si_b->state, si_b->err_type, req->flags, res->flags);
2008-11-30 12:47:21 -05:00
2010-01-29 13:26:18 -05:00
/* this data may be no longer valid, clear it */
2015-04-03 17:46:31 -04:00
if ( s - > txn )
memset ( & s - > txn - > auth , 0 , sizeof ( s - > txn - > auth ) ) ;
2010-01-29 13:26:18 -05:00
2014-06-23 09:22:31 -04:00
/* This flag must explicitly be set every time */
2014-11-28 09:07:47 -05:00
req - > flags & = ~ ( CF_READ_NOEXP | CF_WAKE_WRITE ) ;
res - > flags & = ~ ( CF_READ_NOEXP | CF_WAKE_WRITE ) ;
2009-06-21 16:03:51 -04:00
/* Keep a copy of req/rep flags so that we can detect shutdowns */
2014-11-28 09:07:47 -05:00
rqf_last = req - > flags & ~ CF_MASK_ANALYSER ;
rpf_last = res - > flags & ~ CF_MASK_ANALYSER ;
2009-06-21 16:03:51 -04:00
2009-09-05 14:57:35 -04:00
/* we don't want the stream interface functions to recursively wake us up */
2014-11-28 09:07:47 -05:00
si_f - > flags | = SI_FL_DONT_WAKE ;
si_b - > flags | = SI_FL_DONT_WAKE ;
2009-09-05 14:57:35 -04:00
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
/* update pending events */
s - > pending_events | = ( t - > state & TASK_WOKEN_ANY ) ;
2008-11-30 12:47:21 -05:00
/* 1a: Check for low level timeouts if needed. We just set a flag on
* stream interfaces when their timeouts have expired .
*/
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
if ( unlikely ( s - > pending_events & TASK_WOKEN_TIMER ) ) {
2014-11-28 09:07:47 -05:00
stream_int_check_timeouts ( si_f ) ;
stream_int_check_timeouts ( si_b ) ;
2009-06-21 16:03:51 -04:00
2012-08-27 18:06:31 -04:00
/* check channel timeouts, and close the corresponding stream interfaces
2009-06-21 16:03:51 -04:00
* for future reads or writes . Note : this will also concern upper layers
* but we do not touch any other flag . We must be careful and correctly
* detect state changes when calling them .
*/
2014-11-28 09:07:47 -05:00
channel_check_timeouts ( req ) ;
2009-06-21 16:03:51 -04:00
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( req - > flags & ( CF_SHUTW | CF_WRITE_TIMEOUT ) ) = = CF_WRITE_TIMEOUT ) ) {
si_b - > flags | = SI_FL_NOLINGER ;
si_shutw ( si_b ) ;
2009-12-29 08:49:56 -05:00
}
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( req - > flags & ( CF_SHUTR | CF_READ_TIMEOUT ) ) = = CF_READ_TIMEOUT ) ) {
if ( si_f - > flags & SI_FL_NOHALF )
si_f - > flags | = SI_FL_NOLINGER ;
si_shutr ( si_f ) ;
2012-05-13 08:48:59 -04:00
}
2009-06-21 16:03:51 -04:00
2014-11-28 09:07:47 -05:00
channel_check_timeouts ( res ) ;
2008-11-30 12:47:21 -05:00
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( res - > flags & ( CF_SHUTW | CF_WRITE_TIMEOUT ) ) = = CF_WRITE_TIMEOUT ) ) {
si_f - > flags | = SI_FL_NOLINGER ;
si_shutw ( si_f ) ;
2009-12-29 08:49:56 -05:00
}
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( res - > flags & ( CF_SHUTR | CF_READ_TIMEOUT ) ) = = CF_READ_TIMEOUT ) ) {
if ( si_b - > flags & SI_FL_NOHALF )
si_b - > flags | = SI_FL_NOLINGER ;
si_shutr ( si_b ) ;
2012-05-13 08:48:59 -04:00
}
2012-11-08 08:49:17 -05:00
2016-11-10 08:58:05 -05:00
if ( HAS_FILTERS ( s ) )
flt_stream_check_timeouts ( s ) ;
2012-11-08 08:49:17 -05:00
/* Once in a while we're woken up because the task expires. But
* this does not necessarily mean that a timeout has been reached .
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* So let ' s not run a whole stream processing if only an expiration
2012-11-08 08:49:17 -05:00
* timeout needs to be refreshed .
*/
2014-11-28 09:07:47 -05:00
if ( ! ( ( req - > flags | res - > flags ) &
2012-11-08 08:49:17 -05:00
( CF_SHUTR | CF_READ_ACTIVITY | CF_READ_TIMEOUT | CF_SHUTW |
BUG/MEDIUM: stream-int: Don't loss write's notifs when a stream is woken up
When a write activity is reported on a channel, it is important to keep this
information for the stream because it take part on the analyzers' triggering.
When some data are written, the flag CF_WRITE_PARTIAL is set. It participates to
the task's timeout updates and to the stream's waking. It is also used in
CF_MASK_ANALYSER mask to trigger channels anaylzers. In the past, it was cleared
by process_stream. Because of a bug (fixed in commit 95fad5ba4 ["BUG/MAJOR:
stream-int: don't re-arm recv if send fails"]), It is now cleared before each
send and in stream_int_notify. So it is possible to loss this information when
process_stream is called, preventing analyzers to be called, and possibly
leading to a stalled stream.
Today, this happens in HTTP2 when you call the stat page or when you use the
cache filter. In fact, this happens when the response is sent by an applet. In
HTTP1, everything seems to work as expected.
To fix the problem, we need to make the difference between the write activity
reported to lower layers and the one reported to the stream. So the flag
CF_WRITE_EVENT has been added to notify the stream of the write activity on a
channel. It is set when a send succedded and reset by process_stream. It is also
used in CF_MASK_ANALYSER. finally, it is checked in stream_int_notify to wake up
a stream and in channel_check_timeouts.
This bug is probably present in 1.7 but it seems to have no effect. So for now,
no needs to backport it.
2017-11-09 03:36:43 -05:00
CF_WRITE_ACTIVITY | CF_WRITE_EVENT | CF_WRITE_TIMEOUT | CF_ANA_TIMEOUT ) ) & &
2014-11-28 09:07:47 -05:00
! ( ( si_f - > flags | si_b - > flags ) & ( SI_FL_EXP | SI_FL_ERR ) ) & &
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
( ( s - > pending_events & TASK_WOKEN_ANY ) = = TASK_WOKEN_TIMER ) ) {
2016-05-04 04:18:37 -04:00
si_f - > flags & = ~ SI_FL_DONT_WAKE ;
si_b - > flags & = ~ SI_FL_DONT_WAKE ;
2012-11-08 08:49:17 -05:00
goto update_exp_and_leave ;
2016-05-04 04:18:37 -04:00
}
2009-06-21 16:03:51 -04:00
}
2008-11-30 12:47:21 -05:00
MAJOR: session: only allocate buffers when needed
A session doesn't need buffers all the time, especially when they're
empty. With this patch, we don't allocate buffers anymore when the
session is initialized, we only allocate them in two cases :
- during process_session()
- during I/O operations
During process_session(), we try hard to allocate both buffers at once
so that we know for sure that a started operation can complete. Indeed,
a previous version of this patch used to allocate one buffer at a time,
but it can result in a deadlock when all buffers are allocated for
requests for example, and there's no buffer left to emit error responses.
Here, if any of the buffers cannot be allocated, the whole operation is
cancelled and the session is added at the tail of the buffer wait queue.
At the end of process_session(), a call to session_release_buffers() is
done so that we can offer unused buffers to other sessions waiting for
them.
For I/O operations, we only need to allocate a buffer on the Rx path.
For this, we only allocate a single buffer but ensure that at least two
are available to avoid the deadlock situation. In case buffers are not
available, SI_FL_WAIT_ROOM is set on the stream interface and the session
is queued. Unused buffers resulting either from a successful send() or
from an unused read buffer are offered to pending sessions during the
->wake() callback.
2014-11-25 13:46:36 -05:00
/* below we may emit error messages so we have to ensure that we have
* our buffers properly allocated .
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
if ( ! stream_alloc_work_buffer ( s ) ) {
MAJOR: session: only allocate buffers when needed
A session doesn't need buffers all the time, especially when they're
empty. With this patch, we don't allocate buffers anymore when the
session is initialized, we only allocate them in two cases :
- during process_session()
- during I/O operations
During process_session(), we try hard to allocate both buffers at once
so that we know for sure that a started operation can complete. Indeed,
a previous version of this patch used to allocate one buffer at a time,
but it can result in a deadlock when all buffers are allocated for
requests for example, and there's no buffer left to emit error responses.
Here, if any of the buffers cannot be allocated, the whole operation is
cancelled and the session is added at the tail of the buffer wait queue.
At the end of process_session(), a call to session_release_buffers() is
done so that we can offer unused buffers to other sessions waiting for
them.
For I/O operations, we only need to allocate a buffer on the Rx path.
For this, we only allocate a single buffer but ensure that at least two
are available to avoid the deadlock situation. In case buffers are not
available, SI_FL_WAIT_ROOM is set on the stream interface and the session
is queued. Unused buffers resulting either from a successful send() or
from an unused read buffer are offered to pending sessions during the
->wake() callback.
2014-11-25 13:46:36 -05:00
/* No buffer available, we've been subscribed to the list of
* buffer waiters , let ' s wait for our turn .
*/
2016-05-04 04:18:37 -04:00
si_f - > flags & = ~ SI_FL_DONT_WAKE ;
si_b - > flags & = ~ SI_FL_DONT_WAKE ;
MAJOR: session: only allocate buffers when needed
A session doesn't need buffers all the time, especially when they're
empty. With this patch, we don't allocate buffers anymore when the
session is initialized, we only allocate them in two cases :
- during process_session()
- during I/O operations
During process_session(), we try hard to allocate both buffers at once
so that we know for sure that a started operation can complete. Indeed,
a previous version of this patch used to allocate one buffer at a time,
but it can result in a deadlock when all buffers are allocated for
requests for example, and there's no buffer left to emit error responses.
Here, if any of the buffers cannot be allocated, the whole operation is
cancelled and the session is added at the tail of the buffer wait queue.
At the end of process_session(), a call to session_release_buffers() is
done so that we can offer unused buffers to other sessions waiting for
them.
For I/O operations, we only need to allocate a buffer on the Rx path.
For this, we only allocate a single buffer but ensure that at least two
are available to avoid the deadlock situation. In case buffers are not
available, SI_FL_WAIT_ROOM is set on the stream interface and the session
is queued. Unused buffers resulting either from a successful send() or
from an unused read buffer are offered to pending sessions during the
->wake() callback.
2014-11-25 13:46:36 -05:00
goto update_exp_and_leave ;
}
2008-11-30 12:47:21 -05:00
/* 1b: check for low-level errors reported at the stream interface.
* First we check if it ' s a retryable error ( in which case we don ' t
* want to tell the buffer ) . Otherwise we report the error one level
* upper by setting flags into the buffers . Note that the side towards
* the client cannot have connect ( hence retryable ) errors . Also , the
* connection setup code must be able to deal with any type of abort .
*/
2012-11-11 18:42:33 -05:00
srv = objt_server ( s - > target ) ;
2014-11-28 09:07:47 -05:00
if ( unlikely ( si_f - > flags & SI_FL_ERR ) ) {
if ( si_f - > state = = SI_ST_EST | | si_f - > state = = SI_ST_DIS ) {
si_shutr ( si_f ) ;
si_shutw ( si_f ) ;
stream_int_report_error ( si_f ) ;
if ( ! ( req - > analysers ) & & ! ( res - > analysers ) ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . cli_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . cli_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . cli_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_ERR_MASK ) )
s - > flags | = SF_ERR_CLICL ;
if ( ! ( s - > flags & SF_FINST_MASK ) )
s - > flags | = SF_FINST_D ;
2008-12-14 05:44:04 -05:00
}
2008-11-30 12:47:21 -05:00
}
}
2014-11-28 09:07:47 -05:00
if ( unlikely ( si_b - > flags & SI_FL_ERR ) ) {
if ( si_b - > state = = SI_ST_EST | | si_b - > state = = SI_ST_DIS ) {
si_shutr ( si_b ) ;
si_shutw ( si_b ) ;
stream_int_report_error ( si_b ) ;
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . failed_resp , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . failed_resp , 1 ) ;
2014-11-28 09:07:47 -05:00
if ( ! ( req - > analysers ) & & ! ( res - > analysers ) ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . srv_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . srv_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . srv_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_ERR_MASK ) )
s - > flags | = SF_ERR_SRVCL ;
if ( ! ( s - > flags & SF_FINST_MASK ) )
s - > flags | = SF_FINST_D ;
2008-12-14 05:44:04 -05:00
}
2008-11-30 12:47:21 -05:00
}
/* note: maybe we should process connection errors here ? */
}
2014-11-28 09:07:47 -05:00
if ( si_b - > state = = SI_ST_CON ) {
2008-11-30 12:47:21 -05:00
/* we were trying to establish a connection on the server side,
* maybe it succeeded , maybe it failed , maybe we timed out , . . .
*/
2014-11-28 09:15:44 -05:00
if ( unlikely ( ! sess_update_st_con_tcp ( s ) ) )
sess_update_st_cer ( s ) ;
2014-11-28 09:07:47 -05:00
else if ( si_b - > state = = SI_ST_EST )
2014-11-28 09:15:44 -05:00
sess_establish ( s ) ;
2008-11-30 12:47:21 -05:00
/* state is now one of SI_ST_CON (still in progress), SI_ST_EST
* ( established ) , SI_ST_DIS ( abort ) , SI_ST_CLO ( last error ) ,
* SI_ST_ASS / SI_ST_TAR / SI_ST_REQ for retryable errors .
*/
}
2014-11-28 09:07:47 -05:00
rq_prod_last = si_f - > state ;
rq_cons_last = si_b - > state ;
rp_cons_last = si_f - > state ;
rp_prod_last = si_b - > state ;
2010-07-27 11:15:12 -04:00
resync_stream_interface :
2008-11-30 12:47:21 -05:00
/* Check for connection closure */
DPRINTF ( stderr ,
2012-03-01 12:19:58 -05:00
" [%u] %s:%d: task=%p s=%p, sfl=0x%08x, rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d, cet=0x%x set=0x%x retr=%d \n " ,
2008-11-30 12:47:21 -05:00
now_ms , __FUNCTION__ , __LINE__ ,
t ,
s , s - > flags ,
2014-11-28 09:07:47 -05:00
req , res ,
req - > rex , res - > wex ,
req - > flags , res - > flags ,
req - > buf - > i , req - > buf - > o , res - > buf - > i , res - > buf - > o , si_f - > state , si_b - > state ,
si_f - > err_type , si_b - > err_type ,
si_b - > conn_retries ) ;
2008-11-30 12:47:21 -05:00
/* nothing special to be done on client side */
2014-11-28 09:07:47 -05:00
if ( unlikely ( si_f - > state = = SI_ST_DIS ) )
si_f - > state = SI_ST_CLO ;
2008-11-30 12:47:21 -05:00
/* When a server-side connection is released, we have to count it and
* check for pending connections on this server .
*/
2014-11-28 09:07:47 -05:00
if ( unlikely ( si_b - > state = = SI_ST_DIS ) ) {
si_b - > state = SI_ST_CLO ;
2012-11-11 18:42:33 -05:00
srv = objt_server ( s - > target ) ;
2011-03-10 10:55:02 -05:00
if ( srv ) {
2015-04-02 19:14:29 -04:00
if ( s - > flags & SF_CURR_SESS ) {
s - > flags & = ~ SF_CURR_SESS ;
2017-06-08 08:04:45 -04:00
HA_ATOMIC_SUB ( & srv - > cur_sess , 1 ) ;
2008-11-30 12:47:21 -05:00
}
sess_change_server ( s , NULL ) ;
2011-03-10 10:55:02 -05:00
if ( may_dequeue_tasks ( srv , s - > be ) )
process_srv_queue ( srv ) ;
2008-11-30 12:47:21 -05:00
}
}
/*
* Note : of the transient states ( REQ , CER , DIS ) , only REQ may remain
* at this point .
*/
2009-03-08 14:20:25 -04:00
resync_request :
2008-11-30 12:47:21 -05:00
/* Analyse request */
2014-11-28 09:07:47 -05:00
if ( ( ( req - > flags & ~ rqf_last ) & CF_MASK_ANALYSER ) | |
( ( req - > flags ^ rqf_last ) & CF_MASK_STATIC ) | |
si_f - > state ! = rq_prod_last | |
si_b - > state ! = rq_cons_last | |
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
s - > pending_events & TASK_WOKEN_MSG ) {
2014-11-28 09:07:47 -05:00
unsigned int flags = req - > flags ;
2008-11-30 12:47:21 -05:00
2014-11-28 09:07:47 -05:00
if ( si_f - > state > = SI_ST_EST ) {
2010-01-07 18:32:27 -05:00
int max_loops = global . tune . maxpollevents ;
2010-01-06 17:53:24 -05:00
unsigned int ana_list ;
unsigned int ana_back ;
2009-06-28 13:37:53 -04:00
2010-01-06 18:20:41 -05:00
/* it's up to the analysers to stop new connections,
* disable reading or closing . Note : if an analyser
* disables any of these bits , it is responsible for
* enabling them again when it disables itself , so
* that other analysers are called in similar conditions .
*/
2014-11-28 09:07:47 -05:00
channel_auto_read ( req ) ;
channel_auto_connect ( req ) ;
channel_auto_close ( req ) ;
2008-11-30 17:15:34 -05:00
/* We will call all analysers for which a bit is set in
2014-11-28 09:07:47 -05:00
* req - > analysers , following the bit order from LSB
2008-11-30 17:15:34 -05:00
* to MSB . The analysers must remove themselves from
2009-06-28 13:37:53 -04:00
* the list when not needed . Any analyser may return 0
* to break out of the loop , either because of missing
* data to take a decision , or because it decides to
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* kill the stream . We loop at least once through each
2009-06-28 13:37:53 -04:00
* analyser , and we may loop again if other analysers
* are added in the middle .
2010-01-06 17:53:24 -05:00
*
* We build a list of analysers to run . We evaluate all
* of these analysers in the order of the lower bit to
* the higher bit . This ordering is very important .
* An analyser will often add / remove other analysers ,
* including itself . Any changes to itself have no effect
* on the loop . If it removes any other analysers , we
* want those analysers not to be called anymore during
* this loop . If it adds an analyser that is located
* after itself , we want it to be scheduled for being
* processed during the loop . If it adds an analyser
* which is located before it , we want it to switch to
* it immediately , even if it has already been called
* once but removed since .
*
* In order to achieve this , we compare the analyser
* list after the call with a copy of it before the
* call . The work list is fed with analyser bits that
* appeared during the call . Then we compare previous
* work list with the new one , and check the bits that
* appeared . If the lowest of these bits is lower than
* the current bit , it means we have enabled a previous
* analyser and must immediately loop again .
2008-11-30 17:15:34 -05:00
*/
2009-06-28 13:37:53 -04:00
2014-11-28 09:07:47 -05:00
ana_list = ana_back = req - > analysers ;
2010-01-07 18:32:27 -05:00
while ( ana_list & & max_loops - - ) {
2010-01-06 17:53:24 -05:00
/* Warning! ensure that analysers are always placed in ascending order! */
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
ANALYZE ( s , req , flt_start_analyze , ana_list , ana_back , AN_REQ_FLT_START_FE ) ;
2016-05-11 11:06:28 -04:00
FLT_ANALYZE ( s , req , tcp_inspect_request , ana_list , ana_back , AN_REQ_INSPECT_FE ) ;
FLT_ANALYZE ( s , req , http_wait_for_request , ana_list , ana_back , AN_REQ_WAIT_HTTP ) ;
FLT_ANALYZE ( s , req , http_wait_for_request_body , ana_list , ana_back , AN_REQ_HTTP_BODY ) ;
FLT_ANALYZE ( s , req , http_process_req_common , ana_list , ana_back , AN_REQ_HTTP_PROCESS_FE , sess - > fe ) ;
FLT_ANALYZE ( s , req , process_switching_rules , ana_list , ana_back , AN_REQ_SWITCHING_RULES ) ;
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
ANALYZE ( s , req , flt_start_analyze , ana_list , ana_back , AN_REQ_FLT_START_BE ) ;
2016-05-11 11:06:28 -04:00
FLT_ANALYZE ( s , req , tcp_inspect_request , ana_list , ana_back , AN_REQ_INSPECT_BE ) ;
FLT_ANALYZE ( s , req , http_process_req_common , ana_list , ana_back , AN_REQ_HTTP_PROCESS_BE , s - > be ) ;
FLT_ANALYZE ( s , req , http_process_tarpit , ana_list , ana_back , AN_REQ_HTTP_TARPIT ) ;
FLT_ANALYZE ( s , req , process_server_rules , ana_list , ana_back , AN_REQ_SRV_RULES ) ;
FLT_ANALYZE ( s , req , http_process_request , ana_list , ana_back , AN_REQ_HTTP_INNER ) ;
FLT_ANALYZE ( s , req , tcp_persist_rdp_cookie , ana_list , ana_back , AN_REQ_PRST_RDP_COOKIE ) ;
FLT_ANALYZE ( s , req , process_sticking_rules , ana_list , ana_back , AN_REQ_STICKING_RULES ) ;
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
ANALYZE ( s , req , flt_analyze_http_headers , ana_list , ana_back , AN_REQ_FLT_HTTP_HDRS ) ;
2016-05-11 11:06:28 -04:00
ANALYZE ( s , req , http_request_forward_body , ana_list , ana_back , AN_REQ_HTTP_XFER_BODY ) ;
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
ANALYZE ( s , req , flt_xfer_data , ana_list , ana_back , AN_REQ_FLT_XFER_DATA ) ;
ANALYZE ( s , req , flt_end_analyze , ana_list , ana_back , AN_REQ_FLT_END ) ;
2010-01-07 18:32:27 -05:00
break ;
}
2008-11-30 12:47:21 -05:00
}
2009-03-15 17:34:05 -04:00
2014-11-28 09:07:47 -05:00
rq_prod_last = si_f - > state ;
rq_cons_last = si_b - > state ;
req - > flags & = ~ CF_WAKE_ONCE ;
rqf_last = req - > flags ;
2010-07-27 11:15:12 -04:00
2014-11-28 09:07:47 -05:00
if ( ( req - > flags ^ flags ) & CF_MASK_STATIC )
2009-06-21 16:43:05 -04:00
goto resync_request ;
}
2010-01-06 18:09:04 -05:00
/* we'll monitor the request analysers while parsing the response,
* because some response analysers may indirectly enable new request
* analysers ( eg : HTTP keep - alive ) .
*/
2014-11-28 09:07:47 -05:00
req_ana_back = req - > analysers ;
2010-01-06 18:09:04 -05:00
2009-06-21 16:43:05 -04:00
resync_response :
/* Analyse response */
2014-11-28 09:07:47 -05:00
if ( ( ( res - > flags & ~ rpf_last ) & CF_MASK_ANALYSER ) | |
( res - > flags ^ rpf_last ) & CF_MASK_STATIC | |
si_f - > state ! = rp_cons_last | |
si_b - > state ! = rp_prod_last | |
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
s - > pending_events & TASK_WOKEN_MSG ) {
2014-11-28 09:07:47 -05:00
unsigned int flags = res - > flags ;
2009-06-21 16:43:05 -04:00
2014-11-28 09:07:47 -05:00
if ( si_b - > state > = SI_ST_EST ) {
2010-01-07 18:32:27 -05:00
int max_loops = global . tune . maxpollevents ;
2010-01-06 17:53:24 -05:00
unsigned int ana_list ;
unsigned int ana_back ;
2009-10-18 16:53:08 -04:00
2010-01-06 18:20:41 -05:00
/* it's up to the analysers to stop disable reading or
* closing . Note : if an analyser disables any of these
* bits , it is responsible for enabling them again when
* it disables itself , so that other analysers are called
* in similar conditions .
*/
2014-11-28 09:07:47 -05:00
channel_auto_read ( res ) ;
channel_auto_close ( res ) ;
2009-10-18 16:53:08 -04:00
/* We will call all analysers for which a bit is set in
2014-11-28 09:07:47 -05:00
* res - > analysers , following the bit order from LSB
2009-10-18 16:53:08 -04:00
* to MSB . The analysers must remove themselves from
* the list when not needed . Any analyser may return 0
* to break out of the loop , either because of missing
* data to take a decision , or because it decides to
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* kill the stream . We loop at least once through each
2009-10-18 16:53:08 -04:00
* analyser , and we may loop again if other analysers
* are added in the middle .
*/
2014-11-28 09:07:47 -05:00
ana_list = ana_back = res - > analysers ;
2010-01-07 18:32:27 -05:00
while ( ana_list & & max_loops - - ) {
2010-01-06 17:53:24 -05:00
/* Warning! ensure that analysers are always placed in ascending order! */
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
ANALYZE ( s , res , flt_start_analyze , ana_list , ana_back , AN_RES_FLT_START_FE ) ;
ANALYZE ( s , res , flt_start_analyze , ana_list , ana_back , AN_RES_FLT_START_BE ) ;
2016-05-11 11:06:28 -04:00
FLT_ANALYZE ( s , res , tcp_inspect_response , ana_list , ana_back , AN_RES_INSPECT ) ;
FLT_ANALYZE ( s , res , http_wait_for_response , ana_list , ana_back , AN_RES_WAIT_HTTP ) ;
FLT_ANALYZE ( s , res , process_store_rules , ana_list , ana_back , AN_RES_STORE_RULES ) ;
FLT_ANALYZE ( s , res , http_process_res_common , ana_list , ana_back , AN_RES_HTTP_PROCESS_BE , s - > be ) ;
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
ANALYZE ( s , res , flt_analyze_http_headers , ana_list , ana_back , AN_RES_FLT_HTTP_HDRS ) ;
2016-05-11 11:06:28 -04:00
ANALYZE ( s , res , http_response_forward_body , ana_list , ana_back , AN_RES_HTTP_XFER_BODY ) ;
BUG/MAJOR: channel: Fix the definition order of channel analyzers
It is important to defined analyzers (AN_REQ_* and AN_RES_*) in the same order
they are evaluated in process_stream. This order is really important because
during analyzers evaluation, we run them in the order of the lower bit to the
higher one. This way, when an analyzer adds/removes another one during its
evaluation, we know if it is located before or after it. So, when it adds an
analyzer which is located before it, we can switch to it immediately, even if it
has already been called once but removed since.
With the time, and introduction of new analyzers, this order was broken up. the
main problems come from the filter analyzers. We used values not related with
their evaluation order. Furthermore, we used same values for request and response
analyzers.
So, to fix the bug, filter analyzers have been splitted in 2 distinct lists to
have different analyzers for the request channel than those for the response
channel. And of course, we have moved them to the right place.
Some other analyzers have been reordered to respect the evaluation order:
* AN_REQ_HTTP_TARPIT has been moved just before AN_REQ_SRV_RULES
* AN_REQ_PRST_RDP_COOKIE has been moved just before AN_REQ_STICKING_RULES
* AN_RES_STORE_RULES has been moved just after AN_RES_WAIT_HTTP
Note today we have 29 analyzers, all stored into a 32 bits bitfield. So we can
still add 4 more analyzers before having a problem. A good way to fend off the
problem for a while could be to have a different bitfield for request and
response analyzers.
[wt: all of this must be backported to 1.7, and part of it must be backported
to 1.6 and 1.5]
2017-01-05 08:06:34 -05:00
ANALYZE ( s , res , flt_xfer_data , ana_list , ana_back , AN_RES_FLT_XFER_DATA ) ;
ANALYZE ( s , res , flt_end_analyze , ana_list , ana_back , AN_RES_FLT_END ) ;
2010-01-07 18:32:27 -05:00
break ;
}
2009-06-21 16:43:05 -04:00
}
2014-11-28 09:07:47 -05:00
rp_cons_last = si_f - > state ;
rp_prod_last = si_b - > state ;
2017-07-06 09:49:30 -04:00
res - > flags & = ~ CF_WAKE_ONCE ;
2014-11-28 09:07:47 -05:00
rpf_last = res - > flags ;
2010-07-27 11:15:12 -04:00
2014-11-28 09:07:47 -05:00
if ( ( res - > flags ^ flags ) & CF_MASK_STATIC )
2009-06-21 16:43:05 -04:00
goto resync_response ;
}
2010-01-06 18:09:04 -05:00
/* maybe someone has added some request analysers, so we must check and loop */
2014-11-28 09:07:47 -05:00
if ( req - > analysers & ~ req_ana_back )
2010-01-06 18:09:04 -05:00
goto resync_request ;
2014-11-28 09:07:47 -05:00
if ( ( req - > flags & ~ rqf_last ) & CF_MASK_ANALYSER )
2010-12-17 01:13:42 -05:00
goto resync_request ;
2009-06-21 16:43:05 -04:00
/* FIXME: here we should call protocol handlers which rely on
* both buffers .
*/
/*
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* Now we propagate unhandled errors to the stream . Normally
2010-03-04 14:34:23 -05:00
* we ' re just in a data phase here since it means we have not
* seen any analyser who could set an error status .
2009-06-21 16:43:05 -04:00
*/
2012-11-11 18:42:33 -05:00
srv = objt_server ( s - > target ) ;
2015-04-02 19:14:29 -04:00
if ( unlikely ( ! ( s - > flags & SF_ERR_MASK ) ) ) {
2014-11-28 09:07:47 -05:00
if ( req - > flags & ( CF_READ_ERROR | CF_READ_TIMEOUT | CF_WRITE_ERROR | CF_WRITE_TIMEOUT ) ) {
2009-06-21 16:43:05 -04:00
/* Report it if the client got an error or a read timeout expired */
2014-11-28 09:07:47 -05:00
req - > analysers = 0 ;
if ( req - > flags & CF_READ_ERROR ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . cli_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . cli_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . cli_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_CLICL ;
2010-03-04 14:34:23 -05:00
}
2014-11-28 09:07:47 -05:00
else if ( req - > flags & CF_READ_TIMEOUT ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . cli_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . cli_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . cli_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_CLITO ;
2010-03-04 14:34:23 -05:00
}
2014-11-28 09:07:47 -05:00
else if ( req - > flags & CF_WRITE_ERROR ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . srv_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . srv_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . srv_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_SRVCL ;
2010-03-04 14:34:23 -05:00
}
else {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . srv_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . srv_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . srv_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_SRVTO ;
2010-03-04 14:34:23 -05:00
}
2009-03-15 17:34:05 -04:00
sess_set_term_flags ( s ) ;
}
2014-11-28 09:07:47 -05:00
else if ( res - > flags & ( CF_READ_ERROR | CF_READ_TIMEOUT | CF_WRITE_ERROR | CF_WRITE_TIMEOUT ) ) {
2009-06-21 16:43:05 -04:00
/* Report it if the server got an error or a read timeout expired */
2014-11-28 09:07:47 -05:00
res - > analysers = 0 ;
if ( res - > flags & CF_READ_ERROR ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . srv_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . srv_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . srv_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_SRVCL ;
2010-03-04 14:34:23 -05:00
}
2014-11-28 09:07:47 -05:00
else if ( res - > flags & CF_READ_TIMEOUT ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . srv_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . srv_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . srv_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_SRVTO ;
2010-03-04 14:34:23 -05:00
}
2014-11-28 09:07:47 -05:00
else if ( res - > flags & CF_WRITE_ERROR ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . cli_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . cli_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . cli_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_CLICL ;
2010-03-04 14:34:23 -05:00
}
else {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . cli_aborts , 1 ) ;
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . cli_aborts , 1 ) ;
2011-03-10 10:55:02 -05:00
if ( srv )
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & srv - > counters . cli_aborts , 1 ) ;
2015-04-02 19:14:29 -04:00
s - > flags | = SF_ERR_CLITO ;
2010-03-04 14:34:23 -05:00
}
2009-06-21 16:43:05 -04:00
sess_set_term_flags ( s ) ;
}
2009-03-15 17:34:05 -04:00
}
2009-06-21 16:43:05 -04:00
/*
* Here we take care of forwarding unhandled data . This also includes
* connection establishments and shutdown requests .
*/
2009-03-08 16:38:23 -04:00
/* If noone is interested in analysing data, it's time to forward
2009-09-20 06:07:52 -04:00
* everything . We configure the buffer to forward indefinitely .
2012-08-27 17:14:58 -04:00
* Note that we ' re checking CF_SHUTR_NOW as an indication of a possible
2012-08-27 18:06:31 -04:00
* recent call to channel_abort ( ) .
2008-12-14 11:31:54 -05:00
*/
2017-08-29 10:06:38 -04:00
if ( unlikely ( ( ! req - > analysers | | ( req - > analysers = = AN_REQ_FLT_END & & ! ( req - > flags & CF_FLT_ANALYZE ) ) ) & &
2014-11-28 09:07:47 -05:00
! ( req - > flags & ( CF_SHUTW | CF_SHUTR_NOW ) ) & &
( si_f - > state > = SI_ST_EST ) & &
( req - > to_forward ! = CHN_INFINITE_FORWARD ) ) ) {
2012-11-11 17:05:39 -05:00
/* This buffer is freewheeling, there's no analyser
2009-03-08 16:38:23 -04:00
* attached to it . If any data are left in , we ' ll permit them to
* move .
*/
2014-11-28 09:07:47 -05:00
channel_auto_read ( req ) ;
channel_auto_connect ( req ) ;
channel_auto_close ( req ) ;
buffer_flush ( req - > buf ) ;
2009-03-08 16:38:23 -04:00
2010-11-07 14:26:56 -05:00
/* We'll let data flow between the producer (if still connected)
* to the consumer ( which might possibly not be connected yet ) .
2009-03-08 16:38:23 -04:00
*/
2014-11-28 09:07:47 -05:00
if ( ! ( req - > flags & ( CF_SHUTR | CF_SHUTW_NOW ) ) )
2016-05-04 08:05:58 -04:00
channel_forward_forever ( req ) ;
2015-07-09 12:38:57 -04:00
/* Just in order to support fetching HTTP contents after start
* of forwarding when the HTTP forwarding analyser is not used ,
* we simply reset msg - > sov so that HTTP rewinding points to the
* headers .
*/
if ( s - > txn )
s - > txn - > req . sov = s - > txn - > req . eoh + s - > txn - > req . eol - req - > buf - > o ;
2008-12-14 11:31:54 -05:00
}
2008-12-13 15:12:26 -05:00
2009-03-08 16:38:23 -04:00
/* check if it is wise to enable kernel splicing to forward request data */
2014-11-28 09:07:47 -05:00
if ( ! ( req - > flags & ( CF_KERN_SPLICING | CF_SHUTR ) ) & &
req - > to_forward & &
2009-03-08 16:38:23 -04:00
( global . tune . options & GTUNE_USE_SPLICE ) & &
2017-09-13 12:30:23 -04:00
( objt_cs ( si_f - > end ) & & __objt_cs ( si_f - > end ) - > conn - > xprt & & __objt_cs ( si_f - > end ) - > conn - > xprt - > rcv_pipe ) & &
( objt_cs ( si_b - > end ) & & __objt_cs ( si_b - > end ) - > conn - > xprt & & __objt_cs ( si_b - > end ) - > conn - > xprt - > snd_pipe ) & &
2009-03-08 16:38:23 -04:00
( pipes_used < global . maxpipes ) & &
2015-04-03 09:40:56 -04:00
( ( ( sess - > fe - > options2 | s - > be - > options2 ) & PR_O2_SPLIC_REQ ) | |
( ( ( sess - > fe - > options2 | s - > be - > options2 ) & PR_O2_SPLIC_AUT ) & &
2014-11-28 09:07:47 -05:00
( req - > flags & CF_STREAMER_FAST ) ) ) ) {
req - > flags | = CF_KERN_SPLICING ;
2009-03-08 16:38:23 -04:00
}
2008-11-30 12:47:21 -05:00
/* reflect what the L7 analysers have seen last */
2014-11-28 09:07:47 -05:00
rqf_last = req - > flags ;
2008-11-30 12:47:21 -05:00
/*
* Now forward all shutdown requests between both sides of the buffer
*/
2009-09-19 15:04:57 -04:00
/* first, let's check if the request buffer needs to shutdown(write), which may
* happen either because the input is closed or because we want to force a close
2014-05-10 08:30:07 -04:00
* once the server has begun to respond . If a half - closed timeout is set , we adjust
* the other side ' s timeout as well .
2009-09-19 15:04:57 -04:00
*/
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( req - > flags & ( CF_SHUTW | CF_SHUTW_NOW | CF_AUTO_CLOSE | CF_SHUTR ) ) = =
2014-05-10 08:30:07 -04:00
( CF_AUTO_CLOSE | CF_SHUTR ) ) ) {
2014-11-28 09:07:47 -05:00
channel_shutw_now ( req ) ;
2014-05-10 08:30:07 -04:00
}
2008-11-30 12:47:21 -05:00
/* shutdown(write) pending */
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( req - > flags & ( CF_SHUTW | CF_SHUTW_NOW ) ) = = CF_SHUTW_NOW & &
channel_is_empty ( req ) ) ) {
if ( req - > flags & CF_READ_ERROR )
si_b - > flags | = SI_FL_NOLINGER ;
si_shutw ( si_b ) ;
2013-06-21 02:20:19 -04:00
}
2008-11-30 12:47:21 -05:00
/* shutdown(write) done on server side, we must stop the client too */
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( req - > flags & ( CF_SHUTW | CF_SHUTR | CF_SHUTR_NOW ) ) = = CF_SHUTW & &
! req - > analysers ) )
channel_shutr_now ( req ) ;
2008-11-30 12:47:21 -05:00
/* shutdown(read) pending */
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( req - > flags & ( CF_SHUTR | CF_SHUTR_NOW ) ) = = CF_SHUTR_NOW ) ) {
if ( si_f - > flags & SI_FL_NOHALF )
si_f - > flags | = SI_FL_NOLINGER ;
si_shutr ( si_f ) ;
2012-05-13 08:48:59 -04:00
}
2008-11-30 12:47:21 -05:00
2009-09-19 15:04:57 -04:00
/* it's possible that an upper layer has requested a connection setup or abort.
* There are 2 situations where we decide to establish a new connection :
* - there are data scheduled for emission in the buffer
2012-08-27 17:14:58 -04:00
* - the CF_AUTO_CONNECT flag is set ( active connection )
2009-09-19 15:04:57 -04:00
*/
2014-11-28 09:07:47 -05:00
if ( si_b - > state = = SI_ST_INI ) {
if ( ! ( req - > flags & CF_SHUTW ) ) {
if ( ( req - > flags & CF_AUTO_CONNECT ) | | ! channel_is_empty ( req ) ) {
2013-09-29 11:19:56 -04:00
/* If we have an appctx, there is no connect method, so we
* immediately switch to the connected state , otherwise we
* perform a connection request .
2009-09-19 15:04:57 -04:00
*/
2014-11-28 09:07:47 -05:00
si_b - > state = SI_ST_REQ ; /* new connection requested */
si_b - > conn_retries = s - > be - > conn_retries ;
2009-09-19 15:04:57 -04:00
}
2009-08-16 12:27:24 -04:00
}
2009-09-20 02:19:25 -04:00
else {
2014-11-28 09:07:47 -05:00
si_b - > state = SI_ST_CLO ; /* shutw+ini = abort */
channel_shutw_now ( req ) ; /* fix buffer flags upon abort */
channel_shutr_now ( res ) ;
2009-09-20 02:19:25 -04:00
}
2009-03-06 06:51:23 -05:00
}
2008-11-30 12:47:21 -05:00
/* we may have a pending connection request, or a connection waiting
* for completion .
*/
2014-11-28 09:07:47 -05:00
if ( si_b - > state > = SI_ST_REQ & & si_b - > state < SI_ST_CON ) {
2015-06-06 13:29:07 -04:00
/* prune the request variables and swap to the response variables. */
if ( s - > vars_reqres . scope ! = SCOPE_RES ) {
2016-03-10 10:33:04 -05:00
vars_prune ( & s - > vars_reqres , s - > sess , s ) ;
2015-06-06 13:29:07 -04:00
vars_init ( & s - > vars_reqres , SCOPE_RES ) ;
}
2008-11-30 12:47:21 -05:00
do {
/* nb: step 1 might switch from QUE to ASS, but we first want
* to give a chance to step 2 to perform a redirect if needed .
*/
2014-11-28 09:07:47 -05:00
if ( si_b - > state ! = SI_ST_REQ )
2014-11-28 09:15:44 -05:00
sess_update_stream_int ( s ) ;
2014-11-28 09:07:47 -05:00
if ( si_b - > state = = SI_ST_REQ )
2014-11-28 09:15:44 -05:00
sess_prepare_conn_req ( s ) ;
2008-11-30 12:47:21 -05:00
2013-12-31 17:32:12 -05:00
/* applets directly go to the ESTABLISHED state. Similarly,
* servers experience the same fate when their connection
* is reused .
*/
2014-11-28 09:07:47 -05:00
if ( unlikely ( si_b - > state = = SI_ST_EST ) )
2014-11-28 09:15:44 -05:00
sess_establish ( s ) ;
2013-12-31 17:16:50 -05:00
/* Now we can add the server name to a header (if requested) */
/* check for HTTP mode and proxy server_name_hdr_name != NULL */
BUG/MAJOR: http: don't call http_send_name_header() after an error
A crash was reported when using the "famous" http-send-name-header
directive. This time it's a bit tricky, it requires a certain number of
conditions to be met including maxconn on a server, queuing, timeout in
the queue and cookie-based persistence.
The problem is that in stream.c, before calling http_send_name_header(),
we check a number of conditions to know if we have to replace the header
name. But prior to reaching this place, it's possible for
sess_update_stream_int() to fail and change the stream-int's state to
SI_ST_CLO, send an error 503 to the client, and flush all buffers. But
http_send_name_header() can only be called with valid buffer contents
matching the http_msg's description. So when it rewinds the stream to
modify the header, buf->o becomes negative by the size of the incoming
request and is used as the argument to memmove() which basically
displaces 4GB of memory off a few bytes to write the new name, resulting
in a core and a core file that's really not fun to play with.
The solution obviously consists in refraining from calling this nasty
function when the stream interface is already closed.
This bug also affects 1.5 and possibly 1.4, so the fix must be backported
there.
2015-09-07 13:32:33 -04:00
if ( ( si_b - > state > = SI_ST_CON ) & & ( si_b - > state < SI_ST_CLO ) & &
2013-12-31 17:16:50 -05:00
( s - > be - > server_id_hdr_name ! = NULL ) & &
( s - > be - > mode = = PR_MODE_HTTP ) & &
objt_server ( s - > target ) ) {
2015-04-03 17:46:31 -04:00
http_send_name_header ( s - > txn , s - > be , objt_server ( s - > target ) - > id ) ;
2013-04-07 12:19:16 -04:00
}
2012-11-11 18:42:33 -05:00
srv = objt_server ( s - > target ) ;
2015-04-02 19:14:29 -04:00
if ( si_b - > state = = SI_ST_ASS & & srv & & srv - > rdr_len & & ( s - > flags & SF_REDIRECTABLE ) )
2014-11-28 09:07:47 -05:00
http_perform_server_redirect ( s , si_b ) ;
} while ( si_b - > state = = SI_ST_ASS ) ;
2008-11-30 12:47:21 -05:00
}
2009-06-21 16:43:05 -04:00
/* Benchmarks have shown that it's optimal to do a full resync now */
2014-11-28 09:07:47 -05:00
if ( si_f - > state = = SI_ST_DIS | | si_b - > state = = SI_ST_DIS )
2008-11-30 12:47:21 -05:00
goto resync_stream_interface ;
2010-07-27 11:15:12 -04:00
/* otherwise we want to check if we need to resync the req buffer or not */
2014-11-28 09:07:47 -05:00
if ( ( req - > flags ^ rqf_last ) & CF_MASK_STATIC )
2009-03-08 14:20:25 -04:00
goto resync_request ;
2009-06-21 16:43:05 -04:00
/* perform output updates to the response buffer */
2009-03-15 17:34:05 -04:00
2009-03-08 16:38:23 -04:00
/* If noone is interested in analysing data, it's time to forward
2009-09-20 06:07:52 -04:00
* everything . We configure the buffer to forward indefinitely .
2012-08-27 17:14:58 -04:00
* Note that we ' re checking CF_SHUTR_NOW as an indication of a possible
2012-08-27 18:06:31 -04:00
* recent call to channel_abort ( ) .
2008-12-14 11:31:54 -05:00
*/
2017-08-29 10:06:38 -04:00
if ( unlikely ( ( ! res - > analysers | | ( res - > analysers = = AN_RES_FLT_END & & ! ( res - > flags & CF_FLT_ANALYZE ) ) ) & &
2014-11-28 09:07:47 -05:00
! ( res - > flags & ( CF_SHUTW | CF_SHUTR_NOW ) ) & &
( si_b - > state > = SI_ST_EST ) & &
( res - > to_forward ! = CHN_INFINITE_FORWARD ) ) ) {
2012-11-11 17:05:39 -05:00
/* This buffer is freewheeling, there's no analyser
2009-03-08 16:38:23 -04:00
* attached to it . If any data are left in , we ' ll permit them to
* move .
*/
2014-11-28 09:07:47 -05:00
channel_auto_read ( res ) ;
channel_auto_close ( res ) ;
buffer_flush ( res - > buf ) ;
2010-11-07 14:26:56 -05:00
/* We'll let data flow between the producer (if still connected)
* to the consumer .
*/
2014-11-28 09:07:47 -05:00
if ( ! ( res - > flags & ( CF_SHUTR | CF_SHUTW_NOW ) ) )
2016-05-04 08:05:58 -04:00
channel_forward_forever ( res ) ;
2012-05-12 06:50:00 -04:00
2015-07-09 12:38:57 -04:00
/* Just in order to support fetching HTTP contents after start
* of forwarding when the HTTP forwarding analyser is not used ,
* we simply reset msg - > sov so that HTTP rewinding points to the
* headers .
*/
if ( s - > txn )
s - > txn - > rsp . sov = s - > txn - > rsp . eoh + s - > txn - > rsp . eol - res - > buf - > o ;
2012-05-12 06:50:00 -04:00
/* if we have no analyser anymore in any direction and have a
2014-05-10 08:30:07 -04:00
* tunnel timeout set , use it now . Note that we must respect
* the half - closed timeouts as well .
2012-05-12 06:50:00 -04:00
*/
2014-11-28 09:07:47 -05:00
if ( ! req - > analysers & & s - > be - > timeout . tunnel ) {
req - > rto = req - > wto = res - > rto = res - > wto =
2012-05-12 06:50:00 -04:00
s - > be - > timeout . tunnel ;
2014-05-10 08:30:07 -04:00
2015-04-03 09:40:56 -04:00
if ( ( req - > flags & CF_SHUTR ) & & tick_isset ( sess - > fe - > timeout . clientfin ) )
res - > wto = sess - > fe - > timeout . clientfin ;
2014-11-28 09:07:47 -05:00
if ( ( req - > flags & CF_SHUTW ) & & tick_isset ( s - > be - > timeout . serverfin ) )
res - > rto = s - > be - > timeout . serverfin ;
if ( ( res - > flags & CF_SHUTR ) & & tick_isset ( s - > be - > timeout . serverfin ) )
req - > wto = s - > be - > timeout . serverfin ;
2015-04-03 09:40:56 -04:00
if ( ( res - > flags & CF_SHUTW ) & & tick_isset ( sess - > fe - > timeout . clientfin ) )
req - > rto = sess - > fe - > timeout . clientfin ;
2014-11-28 09:07:47 -05:00
req - > rex = tick_add ( now_ms , req - > rto ) ;
req - > wex = tick_add ( now_ms , req - > wto ) ;
res - > rex = tick_add ( now_ms , res - > rto ) ;
res - > wex = tick_add ( now_ms , res - > wto ) ;
2012-05-12 06:50:00 -04:00
}
2008-12-14 11:31:54 -05:00
}
2008-12-13 15:12:26 -05:00
2009-03-08 16:38:23 -04:00
/* check if it is wise to enable kernel splicing to forward response data */
2014-11-28 09:07:47 -05:00
if ( ! ( res - > flags & ( CF_KERN_SPLICING | CF_SHUTR ) ) & &
res - > to_forward & &
2009-03-08 16:38:23 -04:00
( global . tune . options & GTUNE_USE_SPLICE ) & &
2017-09-13 12:30:23 -04:00
( objt_cs ( si_f - > end ) & & __objt_cs ( si_f - > end ) - > conn - > xprt & & __objt_cs ( si_f - > end ) - > conn - > xprt - > snd_pipe ) & &
( objt_cs ( si_b - > end ) & & __objt_cs ( si_b - > end ) - > conn - > xprt & & __objt_cs ( si_b - > end ) - > conn - > xprt - > rcv_pipe ) & &
2009-03-08 16:38:23 -04:00
( pipes_used < global . maxpipes ) & &
2015-04-03 09:40:56 -04:00
( ( ( sess - > fe - > options2 | s - > be - > options2 ) & PR_O2_SPLIC_RTR ) | |
( ( ( sess - > fe - > options2 | s - > be - > options2 ) & PR_O2_SPLIC_AUT ) & &
2014-11-28 09:07:47 -05:00
( res - > flags & CF_STREAMER_FAST ) ) ) ) {
res - > flags | = CF_KERN_SPLICING ;
2009-03-08 16:38:23 -04:00
}
2008-11-30 12:47:21 -05:00
/* reflect what the L7 analysers have seen last */
2014-11-28 09:07:47 -05:00
rpf_last = res - > flags ;
2008-11-30 12:47:21 -05:00
/*
* Now forward all shutdown requests between both sides of the buffer
*/
/*
* FIXME : this is probably where we should produce error responses .
*/
2008-12-14 11:31:54 -05:00
/* first, let's check if the response buffer needs to shutdown(write) */
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( res - > flags & ( CF_SHUTW | CF_SHUTW_NOW | CF_AUTO_CLOSE | CF_SHUTR ) ) = =
2014-05-10 08:30:07 -04:00
( CF_AUTO_CLOSE | CF_SHUTR ) ) ) {
2014-11-28 09:07:47 -05:00
channel_shutw_now ( res ) ;
2014-05-10 08:30:07 -04:00
}
2008-11-30 12:47:21 -05:00
/* shutdown(write) pending */
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( res - > flags & ( CF_SHUTW | CF_SHUTW_NOW ) ) = = CF_SHUTW_NOW & &
channel_is_empty ( res ) ) ) {
si_shutw ( si_f ) ;
2014-05-10 08:30:07 -04:00
}
2008-11-30 12:47:21 -05:00
/* shutdown(write) done on the client side, we must stop the server too */
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( res - > flags & ( CF_SHUTW | CF_SHUTR | CF_SHUTR_NOW ) ) = = CF_SHUTW ) & &
! res - > analysers )
channel_shutr_now ( res ) ;
2008-11-30 12:47:21 -05:00
/* shutdown(read) pending */
2014-11-28 09:07:47 -05:00
if ( unlikely ( ( res - > flags & ( CF_SHUTR | CF_SHUTR_NOW ) ) = = CF_SHUTR_NOW ) ) {
if ( si_b - > flags & SI_FL_NOHALF )
si_b - > flags | = SI_FL_NOLINGER ;
si_shutr ( si_b ) ;
2012-05-13 08:48:59 -04:00
}
2008-11-30 12:47:21 -05:00
2014-11-28 09:07:47 -05:00
if ( si_f - > state = = SI_ST_DIS | | si_b - > state = = SI_ST_DIS )
2008-11-30 12:47:21 -05:00
goto resync_stream_interface ;
2014-11-28 09:07:47 -05:00
if ( req - > flags ! = rqf_last )
2009-03-08 14:20:25 -04:00
goto resync_request ;
2014-11-28 09:07:47 -05:00
if ( ( res - > flags ^ rpf_last ) & CF_MASK_STATIC )
2009-03-08 14:20:25 -04:00
goto resync_response ;
2008-11-30 12:47:21 -05:00
2009-09-05 14:57:35 -04:00
/* we're interested in getting wakeups again */
2014-11-28 09:07:47 -05:00
si_f - > flags & = ~ SI_FL_DONT_WAKE ;
si_b - > flags & = ~ SI_FL_DONT_WAKE ;
2009-09-05 14:57:35 -04:00
2008-11-30 12:47:21 -05:00
/* This is needed only when debugging is enabled, to indicate
* client - side or server - side close . Please note that in the unlikely
* event where both sides would close at once , the sequence is reported
* on the server side first .
*/
if ( unlikely ( ( global . mode & MODE_DEBUG ) & &
( ! ( global . mode & MODE_QUIET ) | |
( global . mode & MODE_VERBOSE ) ) ) ) {
2014-11-28 09:07:47 -05:00
if ( si_b - > state = = SI_ST_CLO & &
si_b - > prev_state = = SI_ST_EST ) {
2012-10-29 11:51:55 -04:00
chunk_printf ( & trash , " %08x:%s.srvcls[%04x:%04x] \n " ,
2008-11-30 12:47:21 -05:00
s - > uniq_id , s - > be - > id ,
2017-09-13 12:30:23 -04:00
objt_cs ( si_f - > end ) ? ( unsigned short ) objt_cs ( si_f - > end ) - > conn - > handle . fd : - 1 ,
objt_cs ( si_b - > end ) ? ( unsigned short ) objt_cs ( si_b - > end ) - > conn - > handle . fd : - 1 ) ;
2013-12-13 09:14:55 -05:00
shut_your_big_mouth_gcc ( write ( 1 , trash . str , trash . len ) ) ;
2008-11-30 12:47:21 -05:00
}
2014-11-28 09:07:47 -05:00
if ( si_f - > state = = SI_ST_CLO & &
si_f - > prev_state = = SI_ST_EST ) {
2012-10-29 11:51:55 -04:00
chunk_printf ( & trash , " %08x:%s.clicls[%04x:%04x] \n " ,
2008-11-30 12:47:21 -05:00
s - > uniq_id , s - > be - > id ,
2017-09-13 12:30:23 -04:00
objt_cs ( si_f - > end ) ? ( unsigned short ) objt_cs ( si_f - > end ) - > conn - > handle . fd : - 1 ,
objt_cs ( si_b - > end ) ? ( unsigned short ) objt_cs ( si_b - > end ) - > conn - > handle . fd : - 1 ) ;
2013-12-13 09:14:55 -05:00
shut_your_big_mouth_gcc ( write ( 1 , trash . str , trash . len ) ) ;
2008-11-30 12:47:21 -05:00
}
}
2014-11-28 09:07:47 -05:00
if ( likely ( ( si_f - > state ! = SI_ST_CLO ) | |
( si_b - > state > SI_ST_INI & & si_b - > state < SI_ST_CLO ) ) ) {
2008-11-30 12:47:21 -05:00
2015-04-03 09:40:56 -04:00
if ( ( sess - > fe - > options & PR_O_CONTSTATS ) & & ( s - > flags & SF_BE_ASSIGNED ) )
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_process_counters ( s ) ;
2008-11-30 12:47:21 -05:00
2015-04-19 12:13:56 -04:00
if ( si_f - > state = = SI_ST_EST )
2014-11-28 09:07:47 -05:00
si_update ( si_f ) ;
2008-11-30 12:47:21 -05:00
2015-04-19 12:13:56 -04:00
if ( si_b - > state = = SI_ST_EST )
2014-11-28 09:07:47 -05:00
si_update ( si_b ) ;
2008-11-30 12:47:21 -05:00
BUG/MEDIUM: stream-int: Don't loss write's notifs when a stream is woken up
When a write activity is reported on a channel, it is important to keep this
information for the stream because it take part on the analyzers' triggering.
When some data are written, the flag CF_WRITE_PARTIAL is set. It participates to
the task's timeout updates and to the stream's waking. It is also used in
CF_MASK_ANALYSER mask to trigger channels anaylzers. In the past, it was cleared
by process_stream. Because of a bug (fixed in commit 95fad5ba4 ["BUG/MAJOR:
stream-int: don't re-arm recv if send fails"]), It is now cleared before each
send and in stream_int_notify. So it is possible to loss this information when
process_stream is called, preventing analyzers to be called, and possibly
leading to a stalled stream.
Today, this happens in HTTP2 when you call the stat page or when you use the
cache filter. In fact, this happens when the response is sent by an applet. In
HTTP1, everything seems to work as expected.
To fix the problem, we need to make the difference between the write activity
reported to lower layers and the one reported to the stream. So the flag
CF_WRITE_EVENT has been added to notify the stream of the write activity on a
channel. It is set when a send succedded and reset by process_stream. It is also
used in CF_MASK_ANALYSER. finally, it is checked in stream_int_notify to wake up
a stream and in channel_check_timeouts.
This bug is probably present in 1.7 but it seems to have no effect. So for now,
no needs to backport it.
2017-11-09 03:36:43 -05:00
req - > flags & = ~ ( CF_READ_NULL | CF_READ_PARTIAL | CF_WRITE_NULL | CF_WRITE_PARTIAL | CF_READ_ATTACHED | CF_WRITE_EVENT ) ;
res - > flags & = ~ ( CF_READ_NULL | CF_READ_PARTIAL | CF_WRITE_NULL | CF_WRITE_PARTIAL | CF_READ_ATTACHED | CF_WRITE_EVENT ) ;
2014-11-28 09:07:47 -05:00
si_f - > prev_state = si_f - > state ;
si_b - > prev_state = si_b - > state ;
si_f - > flags & = ~ ( SI_FL_ERR | SI_FL_EXP ) ;
si_b - > flags & = ~ ( SI_FL_ERR | SI_FL_EXP ) ;
2008-11-30 12:47:21 -05:00
2014-06-23 09:22:31 -04:00
/* Trick: if a request is being waiting for the server to respond,
* and if we know the server can timeout , we don ' t want the timeout
* to expire on the client side first , but we ' re still interested
* in passing data from the client to the server ( eg : POST ) . Thus ,
* we can cancel the client ' s request timeout if the server ' s
* request timeout is set and the server has not yet sent a response .
*/
2014-11-28 09:07:47 -05:00
if ( ( res - > flags & ( CF_AUTO_CLOSE | CF_SHUTR ) ) = = 0 & &
( tick_isset ( req - > wex ) | | tick_isset ( res - > rex ) ) ) {
req - > flags | = CF_READ_NOEXP ;
req - > rex = TICK_ETERNITY ;
2014-06-23 09:22:31 -04:00
}
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
/* Reset pending events now */
s - > pending_events = 0 ;
2012-11-08 08:49:17 -05:00
update_exp_and_leave :
2016-05-04 04:18:37 -04:00
/* Note: please ensure that if you branch here you disable SI_FL_DONT_WAKE */
2016-11-10 08:58:05 -05:00
t - > expire = tick_first ( ( tick_is_expired ( t - > expire , now_ms ) ? 0 : t - > expire ) ,
tick_first ( tick_first ( req - > rex , req - > wex ) ,
tick_first ( res - > rex , res - > wex ) ) ) ;
2016-11-08 16:03:00 -05:00
if ( ! req - > analysers )
req - > analyse_exp = TICK_ETERNITY ;
if ( ( sess - > fe - > options & PR_O_CONTSTATS ) & & ( s - > flags & SF_BE_ASSIGNED ) & &
( ! tick_isset ( req - > analyse_exp ) | | tick_is_expired ( req - > analyse_exp , now_ms ) ) )
req - > analyse_exp = tick_add ( now_ms , 5000 ) ;
t - > expire = tick_first ( t - > expire , req - > analyse_exp ) ;
2008-11-30 12:47:21 -05:00
2017-11-10 11:14:23 -05:00
t - > expire = tick_first ( t - > expire , res - > analyse_exp ) ;
2014-11-28 09:07:47 -05:00
if ( si_f - > exp )
t - > expire = tick_first ( t - > expire , si_f - > exp ) ;
2008-11-30 12:47:21 -05:00
2014-11-28 09:07:47 -05:00
if ( si_b - > exp )
t - > expire = tick_first ( t - > expire , si_b - > exp ) ;
2008-11-30 12:47:21 -05:00
# ifdef DEBUG_FULL
2009-03-28 05:47:26 -04:00
fprintf ( stderr ,
" [%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u "
" rep->rex=%u rep->wex=%u, si[0].exp=%u, si[1].exp=%u, cs=%d, ss=%d \n " ,
2014-11-28 09:07:47 -05:00
now_ms , t - > expire , req - > rex , req - > wex , req - > analyse_exp ,
res - > rex , res - > wex , si_f - > exp , si_b - > exp , si_f - > state , si_b - > state ) ;
2008-11-30 12:47:21 -05:00
# endif
# ifdef DEBUG_DEV
/* this may only happen when no timeout is set or in case of an FSM bug */
2009-03-08 10:53:06 -04:00
if ( ! tick_isset ( t - > expire ) )
2008-11-30 12:47:21 -05:00
ABORT_NOW ( ) ;
# endif
BUG/MEDIUM: stream: Save unprocessed events for a stream
A stream can be awakened for different reasons. During its processing, it can be
early stopped if no buffer is available. In this situation, the reason why the
stream was awakened is lost, because we rely on the task state, which is reset
after each processing loop.
In many cases, that's not a big deal. But it can be useful to accumulate the
task states if the stream processing is interrupted, especially if some filters
need to be called.
To be clearer, here is an simple example:
1) A stream is awakened with the reason TASK_WOKEN_MSG.
2) Because no buffer is available, the processing is interrupted, the stream
is back to sleep. And the task state is reset.
3) Some buffers become available, so the stream is awakened with the reason
TASK_WOKEN_RES. At this step, the previous reason (TASK_WOKEN_MSG) is lost.
Now, the task states are saved for a stream and reset only when the stream
processing is not interrupted. The correspoing bitfield represents the pending
events for a stream. And we use this one instead of the task state during the
stream processing.
Note that TASK_WOKEN_TIMER and TASK_WOKEN_RES are always removed because these
events are always handled during the stream processing.
[wt: backport to 1.7 and 1.6]
2016-12-08 16:33:52 -05:00
s - > pending_events & = ~ ( TASK_WOKEN_TIMER | TASK_WOKEN_RES ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_release_buffers ( s ) ;
2009-03-08 04:38:41 -04:00
return t ; /* nothing more to do */
2008-11-30 12:47:21 -05:00
}
2015-04-02 19:14:29 -04:00
if ( s - > flags & SF_BE_ASSIGNED )
2017-06-02 09:33:24 -04:00
HA_ATOMIC_SUB ( & s - > be - > beconn , 1 ) ;
2017-09-15 03:07:56 -04:00
2008-11-30 12:47:21 -05:00
if ( unlikely ( ( global . mode & MODE_DEBUG ) & &
( ! ( global . mode & MODE_QUIET ) | | ( global . mode & MODE_VERBOSE ) ) ) ) {
2012-10-29 11:51:55 -04:00
chunk_printf ( & trash , " %08x:%s.closed[%04x:%04x] \n " ,
2008-11-30 12:47:21 -05:00
s - > uniq_id , s - > be - > id ,
2017-09-13 12:30:23 -04:00
objt_cs ( si_f - > end ) ? ( unsigned short ) objt_cs ( si_f - > end ) - > conn - > handle . fd : - 1 ,
objt_cs ( si_b - > end ) ? ( unsigned short ) objt_cs ( si_b - > end ) - > conn - > handle . fd : - 1 ) ;
2013-12-13 09:14:55 -05:00
shut_your_big_mouth_gcc ( write ( 1 , trash . str , trash . len ) ) ;
2008-11-30 12:47:21 -05:00
}
s - > logs . t_close = tv_ms_elapsed ( & s - > logs . tv_accept , & now ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_process_counters ( s ) ;
2008-11-30 12:47:21 -05:00
2015-04-03 17:46:31 -04:00
if ( s - > txn & & s - > txn - > status ) {
2009-10-24 09:36:15 -04:00
int n ;
2015-04-03 17:46:31 -04:00
n = s - > txn - > status / 100 ;
2009-10-24 09:36:15 -04:00
if ( n < 1 | | n > 5 )
n = 0 ;
2015-04-03 09:40:56 -04:00
if ( sess - > fe - > mode = = PR_MODE_HTTP ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & sess - > fe - > fe_counters . p . http . rsp [ n ] , 1 ) ;
2012-11-24 08:54:13 -05:00
}
2015-04-02 19:14:29 -04:00
if ( ( s - > flags & SF_BE_ASSIGNED ) & &
2012-11-24 08:54:13 -05:00
( s - > be - > mode = = PR_MODE_HTTP ) ) {
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & s - > be - > be_counters . p . http . rsp [ n ] , 1 ) ;
HA_ATOMIC_ADD ( & s - > be - > be_counters . p . http . cum_req , 1 ) ;
2012-11-24 08:54:13 -05:00
}
2009-10-24 09:36:15 -04:00
}
2008-11-30 12:47:21 -05:00
/* let's do a final log if we need it */
2015-04-03 09:40:56 -04:00
if ( ! LIST_ISEMPTY ( & sess - > fe - > logformat ) & & s - > logs . logwait & &
2015-04-02 19:14:29 -04:00
! ( s - > flags & SF_MONITOR ) & &
2015-04-03 09:40:56 -04:00
( ! ( sess - > fe - > options & PR_O_NULLNOLOG ) | | req - > total ) ) {
2008-11-30 13:02:32 -05:00
s - > do_log ( s ) ;
2008-11-30 12:47:21 -05:00
}
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* update time stats for this stream */
stream_update_time_stats ( s ) ;
2014-06-17 06:19:18 -04:00
2008-11-30 12:47:21 -05:00
/* the task MUST not be in the run queue anymore */
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_free ( s ) ;
2009-03-08 04:38:41 -04:00
task_delete ( t ) ;
2008-11-30 12:47:21 -05:00
task_free ( t ) ;
2009-03-08 04:38:41 -04:00
return NULL ;
2008-11-30 12:47:21 -05:00
}
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
/* Update the stream's backend and server time stats */
void stream_update_time_stats ( struct stream * s )
2014-06-17 06:19:18 -04:00
{
int t_request ;
int t_queue ;
int t_connect ;
int t_data ;
int t_close ;
struct server * srv ;
t_request = 0 ;
t_queue = s - > logs . t_queue ;
t_connect = s - > logs . t_connect ;
t_close = s - > logs . t_close ;
t_data = s - > logs . t_data ;
if ( s - > be - > mode ! = PR_MODE_HTTP )
t_data = t_connect ;
if ( t_connect < 0 | | t_data < 0 )
return ;
if ( tv_isge ( & s - > logs . tv_request , & s - > logs . tv_accept ) )
t_request = tv_ms_elapsed ( & s - > logs . tv_accept , & s - > logs . tv_request ) ;
t_data - = t_connect ;
t_connect - = t_queue ;
t_queue - = t_request ;
srv = objt_server ( s - > target ) ;
if ( srv ) {
swrate_add ( & srv - > counters . q_time , TIME_STATS_SAMPLES , t_queue ) ;
swrate_add ( & srv - > counters . c_time , TIME_STATS_SAMPLES , t_connect ) ;
swrate_add ( & srv - > counters . d_time , TIME_STATS_SAMPLES , t_data ) ;
swrate_add ( & srv - > counters . t_time , TIME_STATS_SAMPLES , t_close ) ;
}
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( PROXY_LOCK , & s - > be - > lock ) ;
2014-06-17 06:19:18 -04:00
swrate_add ( & s - > be - > be_counters . q_time , TIME_STATS_SAMPLES , t_queue ) ;
swrate_add ( & s - > be - > be_counters . c_time , TIME_STATS_SAMPLES , t_connect ) ;
swrate_add ( & s - > be - > be_counters . d_time , TIME_STATS_SAMPLES , t_data ) ;
swrate_add ( & s - > be - > be_counters . t_time , TIME_STATS_SAMPLES , t_close ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( PROXY_LOCK , & s - > be - > lock ) ;
2014-06-17 06:19:18 -04:00
}
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
/*
* This function adjusts sess - > srv_conn and maintains the previous and new
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* server ' s served stream counts . Setting newsrv to NULL is enough to release
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
* current connection slot . This function also notifies any LB algo which might
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* expect to be informed about any change in the number of active streams on a
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
* server .
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
void sess_change_server ( struct stream * sess , struct server * newsrv )
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
{
if ( sess - > srv_conn = = newsrv )
return ;
if ( sess - > srv_conn ) {
2017-06-08 08:04:45 -04:00
HA_ATOMIC_SUB ( & sess - > srv_conn - > served , 1 ) ;
2017-06-02 09:33:24 -04:00
HA_ATOMIC_SUB ( & sess - > srv_conn - > proxy - > served , 1 ) ;
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
if ( sess - > srv_conn - > proxy - > lbprm . server_drop_conn )
sess - > srv_conn - > proxy - > lbprm . server_drop_conn ( sess - > srv_conn ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_del_srv_conn ( sess ) ;
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
}
if ( newsrv ) {
2017-06-08 08:04:45 -04:00
HA_ATOMIC_ADD ( & newsrv - > served , 1 ) ;
2017-06-02 09:33:24 -04:00
HA_ATOMIC_ADD ( & newsrv - > proxy - > served , 1 ) ;
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
if ( newsrv - > proxy - > lbprm . server_take_conn )
newsrv - > proxy - > lbprm . server_take_conn ( newsrv ) ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream_add_srv_conn ( sess , newsrv ) ;
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
}
}
2009-03-15 17:34:05 -04:00
/* Handle server-side errors for default protocols. It is called whenever a a
* connection setup is aborted or a request is aborted in queue . It sets the
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
* stream termination flags so that the caller does not have to worry about
2009-03-15 17:34:05 -04:00
* them . It ' s installed as - > srv_error for the server - side stream_interface .
*/
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
void default_srv_error ( struct stream * s , struct stream_interface * si )
2009-03-15 17:34:05 -04:00
{
int err_type = si - > err_type ;
int err = 0 , fin = 0 ;
if ( err_type & SI_ET_QUEUE_ABRT ) {
2015-04-02 19:14:29 -04:00
err = SF_ERR_CLICL ;
fin = SF_FINST_Q ;
2009-03-15 17:34:05 -04:00
}
else if ( err_type & SI_ET_CONN_ABRT ) {
2015-04-02 19:14:29 -04:00
err = SF_ERR_CLICL ;
fin = SF_FINST_C ;
2009-03-15 17:34:05 -04:00
}
else if ( err_type & SI_ET_QUEUE_TO ) {
2015-04-02 19:14:29 -04:00
err = SF_ERR_SRVTO ;
fin = SF_FINST_Q ;
2009-03-15 17:34:05 -04:00
}
else if ( err_type & SI_ET_QUEUE_ERR ) {
2015-04-02 19:14:29 -04:00
err = SF_ERR_SRVCL ;
fin = SF_FINST_Q ;
2009-03-15 17:34:05 -04:00
}
else if ( err_type & SI_ET_CONN_TO ) {
2015-04-02 19:14:29 -04:00
err = SF_ERR_SRVTO ;
fin = SF_FINST_C ;
2009-03-15 17:34:05 -04:00
}
else if ( err_type & SI_ET_CONN_ERR ) {
2015-04-02 19:14:29 -04:00
err = SF_ERR_SRVCL ;
fin = SF_FINST_C ;
2009-03-15 17:34:05 -04:00
}
2012-05-14 06:11:47 -04:00
else if ( err_type & SI_ET_CONN_RES ) {
2015-04-02 19:14:29 -04:00
err = SF_ERR_RESOURCE ;
fin = SF_FINST_C ;
2012-05-14 06:11:47 -04:00
}
2009-03-15 17:34:05 -04:00
else /* SI_ET_CONN_OTHER and others */ {
2015-04-02 19:14:29 -04:00
err = SF_ERR_INTERNAL ;
fin = SF_FINST_C ;
2009-03-15 17:34:05 -04:00
}
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_ERR_MASK ) )
2009-03-15 17:34:05 -04:00
s - > flags | = err ;
2015-04-02 19:14:29 -04:00
if ( ! ( s - > flags & SF_FINST_MASK ) )
2009-03-15 17:34:05 -04:00
s - > flags | = fin ;
}
[BUG] fix the dequeuing logic to ensure that all requests get served
The dequeuing logic was completely wrong. First, a task was assigned
to all servers to process the queue, but this task was never scheduled
and was only woken up on session free. Second, there was no reservation
of server entries when a task was assigned a server. This means that
as long as the task was not connected to the server, its presence was
not accounted for. This was causing trouble when detecting whether or
not a server had reached maxconn. Third, during a redispatch, a session
could lose its place at the server's and get blocked because another
session at the same moment would have stolen the entry. Fourth, the
redispatch option did not work when maxqueue was reached for a server,
and it was not possible to do so without indefinitely hanging a session.
The root cause of all those problems was the lack of pre-reservation of
connections at the server's, and the lack of tracking of servers during
a redispatch. Everything relied on combinations of flags which could
appear similarly in quite distinct situations.
This patch is a major rework but there was no other solution, as the
internal logic was deeply flawed. The resulting code is cleaner, more
understandable, uses less magics and is overall more robust.
As an added bonus, "option redispatch" now works when maxqueue has
been reached on a server.
2008-06-20 09:04:11 -04:00
2015-04-02 19:14:29 -04:00
/* kill a stream and set the termination flags to <why> (one of SF_ERR_*) */
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
void stream_shutdown ( struct stream * stream , int why )
2011-09-07 17:01:56 -04:00
{
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
if ( stream - > req . flags & ( CF_SHUTW | CF_SHUTW_NOW ) )
2011-09-07 17:01:56 -04:00
return ;
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
channel_shutw_now ( & stream - > req ) ;
channel_shutr_now ( & stream - > res ) ;
stream - > task - > nice = 1024 ;
2015-04-02 19:14:29 -04:00
if ( ! ( stream - > flags & SF_ERR_MASK ) )
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
stream - > flags | = why ;
task_wakeup ( stream - > task , TASK_WOKEN_OTHER ) ;
2011-09-07 17:01:56 -04:00
}
2010-06-14 15:04:55 -04:00
2010-06-18 11:46:06 -04:00
/************************************************************************/
/* All supported ACL keywords must be declared here. */
/************************************************************************/
2015-09-27 13:29:33 -04:00
/* 0=OK, <0=Alert, >0=Warning */
static enum act_parse_ret stream_parse_use_service ( const char * * args , int * cur_arg ,
struct proxy * px , struct act_rule * rule ,
char * * err )
{
struct action_kw * kw ;
/* Check if the service name exists. */
if ( * ( args [ * cur_arg ] ) = = 0 ) {
memprintf ( err , " '%s' expects a service name. " , args [ 0 ] ) ;
2015-11-26 13:48:04 -05:00
return ACT_RET_PRS_ERR ;
2015-09-27 13:29:33 -04:00
}
/* lookup for keyword corresponding to a service. */
kw = action_lookup ( & service_keywords , args [ * cur_arg ] ) ;
if ( ! kw ) {
memprintf ( err , " '%s' unknown service name. " , args [ 1 ] ) ;
return ACT_RET_PRS_ERR ;
}
( * cur_arg ) + + ;
/* executes specific rule parser. */
rule - > kw = kw ;
if ( kw - > parse ( ( const char * * ) args , cur_arg , px , rule , err ) = = ACT_RET_PRS_ERR )
return ACT_RET_PRS_ERR ;
/* Register processing function. */
rule - > action_ptr = process_use_service ;
rule - > action = ACT_CUSTOM ;
return ACT_RET_PRS_OK ;
}
void service_keywords_register ( struct action_kw_list * kw_list )
{
LIST_ADDQ ( & service_keywords , & kw_list - > list ) ;
}
2016-11-21 02:51:11 -05:00
/* This function dumps a complete stream state onto the stream interface's
* read buffer . The stream has to be set in strm . It returns 0 if the output
* buffer is full and it needs to be called again , otherwise non - zero . It is
* designed to be called from stats_dump_strm_to_buffer ( ) below .
*/
static int stats_dump_full_strm_to_buffer ( struct stream_interface * si , struct stream * strm )
{
struct appctx * appctx = __objt_appctx ( si - > end ) ;
struct tm tm ;
extern const char * monthname [ 12 ] ;
char pn [ INET6_ADDRSTRLEN ] ;
2017-09-13 12:30:23 -04:00
struct conn_stream * cs ;
2016-11-21 02:51:11 -05:00
struct connection * conn ;
struct appctx * tmpctx ;
chunk_reset ( & trash ) ;
if ( appctx - > ctx . sess . section > 0 & & appctx - > ctx . sess . uid ! = strm - > uniq_id ) {
/* stream changed, no need to go any further */
chunk_appendf ( & trash , " *** session terminated while we were watching it *** \n " ) ;
REORG: channel: finally rename the last bi_* / bo_* functions
For HTTP/2 we'll need some buffer-only equivalent functions to some of
the ones applying to channels and still squatting the bi_* / bo_*
namespace. Since these names have kept being misleading for quite some
time now and are really getting annoying, it's time to rename them. This
commit will use "ci/co" as the prefix (for "channel in", "channel out")
instead of "bi/bo". The following ones were renamed :
bi_getblk_nc, bi_getline_nc, bi_putblk, bi_putchr,
bo_getblk, bo_getblk_nc, bo_getline, bo_getline_nc, bo_inject,
bi_putchk, bi_putstr, bo_getchr, bo_skip, bi_swpbuf
2017-10-19 08:32:15 -04:00
if ( ci_putchk ( si_ic ( si ) , & trash ) = = - 1 ) {
2016-11-21 02:51:11 -05:00
si_applet_cant_put ( si ) ;
return 0 ;
}
appctx - > ctx . sess . uid = 0 ;
appctx - > ctx . sess . section = 0 ;
return 1 ;
}
switch ( appctx - > ctx . sess . section ) {
case 0 : /* main status of the stream */
appctx - > ctx . sess . uid = strm - > uniq_id ;
appctx - > ctx . sess . section = 1 ;
/* fall through */
case 1 :
get_localtime ( strm - > logs . accept_date . tv_sec , & tm ) ;
chunk_appendf ( & trash ,
" %p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s " ,
strm ,
tm . tm_mday , monthname [ tm . tm_mon ] , tm . tm_year + 1900 ,
tm . tm_hour , tm . tm_min , tm . tm_sec , ( int ) ( strm - > logs . accept_date . tv_usec ) ,
strm - > uniq_id ,
strm_li ( strm ) ? strm_li ( strm ) - > proto - > name : " ? " ) ;
conn = objt_conn ( strm_orig ( strm ) ) ;
switch ( conn ? addr_to_str ( & conn - > addr . from , pn , sizeof ( pn ) ) : AF_UNSPEC ) {
case AF_INET :
case AF_INET6 :
chunk_appendf ( & trash , " source=%s:%d \n " ,
pn , get_host_port ( & conn - > addr . from ) ) ;
break ;
case AF_UNIX :
chunk_appendf ( & trash , " source=unix:%d \n " , strm_li ( strm ) - > luid ) ;
break ;
default :
/* no more information to print right now */
chunk_appendf ( & trash , " \n " ) ;
break ;
}
chunk_appendf ( & trash ,
" flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p \n " ,
strm - > flags , strm - > si [ 1 ] . conn_retries , strm - > srv_conn , strm - > pend_pos ) ;
chunk_appendf ( & trash ,
" frontend=%s (id=%u mode=%s), listener=%s (id=%u) " ,
strm_fe ( strm ) - > id , strm_fe ( strm ) - > uuid , strm_fe ( strm ) - > mode ? " http " : " tcp " ,
strm_li ( strm ) ? strm_li ( strm ) - > name ? strm_li ( strm ) - > name : " ? " : " ? " ,
strm_li ( strm ) ? strm_li ( strm ) - > luid : 0 ) ;
if ( conn )
conn_get_to_addr ( conn ) ;
switch ( conn ? addr_to_str ( & conn - > addr . to , pn , sizeof ( pn ) ) : AF_UNSPEC ) {
case AF_INET :
case AF_INET6 :
chunk_appendf ( & trash , " addr=%s:%d \n " ,
pn , get_host_port ( & conn - > addr . to ) ) ;
break ;
case AF_UNIX :
chunk_appendf ( & trash , " addr=unix:%d \n " , strm_li ( strm ) - > luid ) ;
break ;
default :
/* no more information to print right now */
chunk_appendf ( & trash , " \n " ) ;
break ;
}
if ( strm - > be - > cap & PR_CAP_BE )
chunk_appendf ( & trash ,
" backend=%s (id=%u mode=%s) " ,
strm - > be - > id ,
strm - > be - > uuid , strm - > be - > mode ? " http " : " tcp " ) ;
else
chunk_appendf ( & trash , " backend=<NONE> (id=-1 mode=-) " ) ;
2017-09-13 12:30:23 -04:00
cs = objt_cs ( strm - > si [ 1 ] . end ) ;
conn = cs_conn ( cs ) ;
2016-11-21 02:51:11 -05:00
if ( conn )
conn_get_from_addr ( conn ) ;
switch ( conn ? addr_to_str ( & conn - > addr . from , pn , sizeof ( pn ) ) : AF_UNSPEC ) {
case AF_INET :
case AF_INET6 :
chunk_appendf ( & trash , " addr=%s:%d \n " ,
pn , get_host_port ( & conn - > addr . from ) ) ;
break ;
case AF_UNIX :
chunk_appendf ( & trash , " addr=unix \n " ) ;
break ;
default :
/* no more information to print right now */
chunk_appendf ( & trash , " \n " ) ;
break ;
}
if ( strm - > be - > cap & PR_CAP_BE )
chunk_appendf ( & trash ,
" server=%s (id=%u) " ,
objt_server ( strm - > target ) ? objt_server ( strm - > target ) - > id : " <none> " ,
objt_server ( strm - > target ) ? objt_server ( strm - > target ) - > puid : 0 ) ;
else
chunk_appendf ( & trash , " server=<NONE> (id=-1) " ) ;
if ( conn )
conn_get_to_addr ( conn ) ;
switch ( conn ? addr_to_str ( & conn - > addr . to , pn , sizeof ( pn ) ) : AF_UNSPEC ) {
case AF_INET :
case AF_INET6 :
chunk_appendf ( & trash , " addr=%s:%d \n " ,
pn , get_host_port ( & conn - > addr . to ) ) ;
break ;
case AF_UNIX :
chunk_appendf ( & trash , " addr=unix \n " ) ;
break ;
default :
/* no more information to print right now */
chunk_appendf ( & trash , " \n " ) ;
break ;
}
chunk_appendf ( & trash ,
" task=%p (state=0x%02x nice=%d calls=%d exp=%s%s " ,
strm - > task ,
strm - > task - > state ,
strm - > task - > nice , strm - > task - > calls ,
strm - > task - > expire ?
tick_is_expired ( strm - > task - > expire , now_ms ) ? " <PAST> " :
human_time ( TICKS_TO_MS ( strm - > task - > expire - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ,
task_in_rq ( strm - > task ) ? " , running " : " " ) ;
chunk_appendf ( & trash ,
" age=%s) \n " ,
human_time ( now . tv_sec - strm - > logs . accept_date . tv_sec , 1 ) ) ;
if ( strm - > txn )
chunk_appendf ( & trash ,
" txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s waiting=%d \n " ,
strm - > txn , strm - > txn - > flags , strm - > txn - > meth , strm - > txn - > status ,
2017-09-21 03:30:46 -04:00
h1_msg_state_str ( strm - > txn - > req . msg_state ) , h1_msg_state_str ( strm - > txn - > rsp . msg_state ) , ! LIST_ISEMPTY ( & strm - > buffer_wait . list ) ) ;
2016-11-21 02:51:11 -05:00
chunk_appendf ( & trash ,
" si[0]=%p (state=%s flags=0x%02x endp0=%s:%p exp=%s, et=0x%03x) \n " ,
& strm - > si [ 0 ] ,
si_state_str ( strm - > si [ 0 ] . state ) ,
strm - > si [ 0 ] . flags ,
obj_type_name ( strm - > si [ 0 ] . end ) ,
obj_base_ptr ( strm - > si [ 0 ] . end ) ,
strm - > si [ 0 ] . exp ?
tick_is_expired ( strm - > si [ 0 ] . exp , now_ms ) ? " <PAST> " :
human_time ( TICKS_TO_MS ( strm - > si [ 0 ] . exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ,
strm - > si [ 0 ] . err_type ) ;
chunk_appendf ( & trash ,
" si[1]=%p (state=%s flags=0x%02x endp1=%s:%p exp=%s, et=0x%03x) \n " ,
& strm - > si [ 1 ] ,
si_state_str ( strm - > si [ 1 ] . state ) ,
strm - > si [ 1 ] . flags ,
obj_type_name ( strm - > si [ 1 ] . end ) ,
obj_base_ptr ( strm - > si [ 1 ] . end ) ,
strm - > si [ 1 ] . exp ?
tick_is_expired ( strm - > si [ 1 ] . exp , now_ms ) ? " <PAST> " :
human_time ( TICKS_TO_MS ( strm - > si [ 1 ] . exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ,
strm - > si [ 1 ] . err_type ) ;
2017-09-13 12:30:23 -04:00
if ( ( cs = objt_cs ( strm - > si [ 0 ] . end ) ) ! = NULL ) {
conn = cs - > conn ;
2016-11-21 02:51:11 -05:00
chunk_appendf ( & trash ,
MEDIUM: connection: start to introduce a mux layer between xprt and data
For HTTP/2 and QUIC, we'll need to deal with multiplexed streams inside
a connection. After quite a long brainstorming, it appears that the
connection interface to the existing streams is appropriate just like
the connection interface to the lower layers. In fact we need to have
the mux layer in the middle of the connection, between the transport
and the data layer.
A mux can exist on two directions/sides. On the inbound direction, it
instanciates new streams from incoming connections, while on the outbound
direction it muxes streams into outgoing connections. The difference is
visible on the mux->init() call : in one case, an upper context is already
known (outgoing connection), and in the other case, the upper context is
not yet known (incoming connection) and will have to be allocated by the
mux. The session doesn't have to create the new streams anymore, as this
is performed by the mux itself.
This patch introduces this and creates a pass-through mux called
"mux_pt" which is used for all new connections and which only
calls the data layer's recv,send,wake() calls. One incoming stream
is immediately created when init() is called on the inbound direction.
There should not be any visible impact.
Note that the connection's mux is purposely not set until the session
is completed so that we don't accidently run with the wrong mux. This
must not cause any issue as the xprt_done_cb function is always called
prior to using mux's recv/send functions.
2017-08-28 04:53:00 -04:00
" co0=%p ctrl=%s xprt=%s mux=%s data=%s target=%s:%p \n " ,
2016-11-21 02:51:11 -05:00
conn ,
conn_get_ctrl_name ( conn ) ,
conn_get_xprt_name ( conn ) ,
MEDIUM: connection: start to introduce a mux layer between xprt and data
For HTTP/2 and QUIC, we'll need to deal with multiplexed streams inside
a connection. After quite a long brainstorming, it appears that the
connection interface to the existing streams is appropriate just like
the connection interface to the lower layers. In fact we need to have
the mux layer in the middle of the connection, between the transport
and the data layer.
A mux can exist on two directions/sides. On the inbound direction, it
instanciates new streams from incoming connections, while on the outbound
direction it muxes streams into outgoing connections. The difference is
visible on the mux->init() call : in one case, an upper context is already
known (outgoing connection), and in the other case, the upper context is
not yet known (incoming connection) and will have to be allocated by the
mux. The session doesn't have to create the new streams anymore, as this
is performed by the mux itself.
This patch introduces this and creates a pass-through mux called
"mux_pt" which is used for all new connections and which only
calls the data layer's recv,send,wake() calls. One incoming stream
is immediately created when init() is called on the inbound direction.
There should not be any visible impact.
Note that the connection's mux is purposely not set until the session
is completed so that we don't accidently run with the wrong mux. This
must not cause any issue as the xprt_done_cb function is always called
prior to using mux's recv/send functions.
2017-08-28 04:53:00 -04:00
conn_get_mux_name ( conn ) ,
2017-09-13 12:30:23 -04:00
cs_get_data_name ( cs ) ,
2016-11-21 02:51:11 -05:00
obj_type_name ( conn - > target ) ,
obj_base_ptr ( conn - > target ) ) ;
chunk_appendf ( & trash ,
" flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d \n " ,
conn - > flags ,
2017-08-24 08:31:19 -04:00
conn - > handle . fd ,
conn - > handle . fd > = 0 ? fdtab [ conn - > handle . fd ] . state : 0 ,
conn - > handle . fd > = 0 ? fdtab [ conn - > handle . fd ] . cache : 0 ,
conn - > handle . fd > = 0 ? fdtab [ conn - > handle . fd ] . updated : 0 ) ;
2016-11-21 02:51:11 -05:00
}
else if ( ( tmpctx = objt_appctx ( strm - > si [ 0 ] . end ) ) ! = NULL ) {
chunk_appendf ( & trash ,
" app0=%p st0=%d st1=%d st2=%d applet=%s \n " ,
tmpctx ,
tmpctx - > st0 ,
tmpctx - > st1 ,
tmpctx - > st2 ,
tmpctx - > applet - > name ) ;
}
2017-09-13 12:30:23 -04:00
if ( ( cs = objt_cs ( strm - > si [ 1 ] . end ) ) ! = NULL ) {
conn = cs - > conn ;
2016-11-21 02:51:11 -05:00
chunk_appendf ( & trash ,
MEDIUM: connection: start to introduce a mux layer between xprt and data
For HTTP/2 and QUIC, we'll need to deal with multiplexed streams inside
a connection. After quite a long brainstorming, it appears that the
connection interface to the existing streams is appropriate just like
the connection interface to the lower layers. In fact we need to have
the mux layer in the middle of the connection, between the transport
and the data layer.
A mux can exist on two directions/sides. On the inbound direction, it
instanciates new streams from incoming connections, while on the outbound
direction it muxes streams into outgoing connections. The difference is
visible on the mux->init() call : in one case, an upper context is already
known (outgoing connection), and in the other case, the upper context is
not yet known (incoming connection) and will have to be allocated by the
mux. The session doesn't have to create the new streams anymore, as this
is performed by the mux itself.
This patch introduces this and creates a pass-through mux called
"mux_pt" which is used for all new connections and which only
calls the data layer's recv,send,wake() calls. One incoming stream
is immediately created when init() is called on the inbound direction.
There should not be any visible impact.
Note that the connection's mux is purposely not set until the session
is completed so that we don't accidently run with the wrong mux. This
must not cause any issue as the xprt_done_cb function is always called
prior to using mux's recv/send functions.
2017-08-28 04:53:00 -04:00
" co1=%p ctrl=%s xprt=%s mux=%s data=%s target=%s:%p \n " ,
2016-11-21 02:51:11 -05:00
conn ,
conn_get_ctrl_name ( conn ) ,
conn_get_xprt_name ( conn ) ,
MEDIUM: connection: start to introduce a mux layer between xprt and data
For HTTP/2 and QUIC, we'll need to deal with multiplexed streams inside
a connection. After quite a long brainstorming, it appears that the
connection interface to the existing streams is appropriate just like
the connection interface to the lower layers. In fact we need to have
the mux layer in the middle of the connection, between the transport
and the data layer.
A mux can exist on two directions/sides. On the inbound direction, it
instanciates new streams from incoming connections, while on the outbound
direction it muxes streams into outgoing connections. The difference is
visible on the mux->init() call : in one case, an upper context is already
known (outgoing connection), and in the other case, the upper context is
not yet known (incoming connection) and will have to be allocated by the
mux. The session doesn't have to create the new streams anymore, as this
is performed by the mux itself.
This patch introduces this and creates a pass-through mux called
"mux_pt" which is used for all new connections and which only
calls the data layer's recv,send,wake() calls. One incoming stream
is immediately created when init() is called on the inbound direction.
There should not be any visible impact.
Note that the connection's mux is purposely not set until the session
is completed so that we don't accidently run with the wrong mux. This
must not cause any issue as the xprt_done_cb function is always called
prior to using mux's recv/send functions.
2017-08-28 04:53:00 -04:00
conn_get_mux_name ( conn ) ,
2017-09-13 12:30:23 -04:00
cs_get_data_name ( cs ) ,
2016-11-21 02:51:11 -05:00
obj_type_name ( conn - > target ) ,
obj_base_ptr ( conn - > target ) ) ;
chunk_appendf ( & trash ,
" flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d \n " ,
conn - > flags ,
2017-08-24 08:31:19 -04:00
conn - > handle . fd ,
conn - > handle . fd > = 0 ? fdtab [ conn - > handle . fd ] . state : 0 ,
conn - > handle . fd > = 0 ? fdtab [ conn - > handle . fd ] . cache : 0 ,
conn - > handle . fd > = 0 ? fdtab [ conn - > handle . fd ] . updated : 0 ) ;
2016-11-21 02:51:11 -05:00
}
else if ( ( tmpctx = objt_appctx ( strm - > si [ 1 ] . end ) ) ! = NULL ) {
chunk_appendf ( & trash ,
" app1=%p st0=%d st1=%d st2=%d applet=%s \n " ,
tmpctx ,
tmpctx - > st0 ,
tmpctx - > st1 ,
tmpctx - > st2 ,
tmpctx - > applet - > name ) ;
}
chunk_appendf ( & trash ,
" req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld) \n "
" an_exp=%s " ,
& strm - > req ,
strm - > req . flags , strm - > req . analysers ,
strm - > req . pipe ? strm - > req . pipe - > data : 0 ,
strm - > req . to_forward , strm - > req . total ,
strm - > req . analyse_exp ?
human_time ( TICKS_TO_MS ( strm - > req . analyse_exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ) ;
chunk_appendf ( & trash ,
" rex=%s " ,
strm - > req . rex ?
human_time ( TICKS_TO_MS ( strm - > req . rex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ) ;
chunk_appendf ( & trash ,
" wex=%s \n "
" buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d \n " ,
strm - > req . wex ?
human_time ( TICKS_TO_MS ( strm - > req . wex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ,
strm - > req . buf ,
strm - > req . buf - > data , strm - > req . buf - > o ,
( int ) ( strm - > req . buf - > p - strm - > req . buf - > data ) ,
strm - > txn ? strm - > txn - > req . next : 0 , strm - > req . buf - > i ,
strm - > req . buf - > size ) ;
chunk_appendf ( & trash ,
" res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld) \n "
" an_exp=%s " ,
& strm - > res ,
strm - > res . flags , strm - > res . analysers ,
strm - > res . pipe ? strm - > res . pipe - > data : 0 ,
strm - > res . to_forward , strm - > res . total ,
strm - > res . analyse_exp ?
human_time ( TICKS_TO_MS ( strm - > res . analyse_exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ) ;
chunk_appendf ( & trash ,
" rex=%s " ,
strm - > res . rex ?
human_time ( TICKS_TO_MS ( strm - > res . rex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ) ;
chunk_appendf ( & trash ,
" wex=%s \n "
" buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d \n " ,
strm - > res . wex ?
human_time ( TICKS_TO_MS ( strm - > res . wex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " <NEVER> " ,
strm - > res . buf ,
strm - > res . buf - > data , strm - > res . buf - > o ,
( int ) ( strm - > res . buf - > p - strm - > res . buf - > data ) ,
strm - > txn ? strm - > txn - > rsp . next : 0 , strm - > res . buf - > i ,
strm - > res . buf - > size ) ;
REORG: channel: finally rename the last bi_* / bo_* functions
For HTTP/2 we'll need some buffer-only equivalent functions to some of
the ones applying to channels and still squatting the bi_* / bo_*
namespace. Since these names have kept being misleading for quite some
time now and are really getting annoying, it's time to rename them. This
commit will use "ci/co" as the prefix (for "channel in", "channel out")
instead of "bi/bo". The following ones were renamed :
bi_getblk_nc, bi_getline_nc, bi_putblk, bi_putchr,
bo_getblk, bo_getblk_nc, bo_getline, bo_getline_nc, bo_inject,
bi_putchk, bi_putstr, bo_getchr, bo_skip, bi_swpbuf
2017-10-19 08:32:15 -04:00
if ( ci_putchk ( si_ic ( si ) , & trash ) = = - 1 ) {
2016-11-21 02:51:11 -05:00
si_applet_cant_put ( si ) ;
return 0 ;
}
/* use other states to dump the contents */
}
/* end of dump */
appctx - > ctx . sess . uid = 0 ;
appctx - > ctx . sess . section = 0 ;
return 1 ;
}
static int cli_parse_show_sess ( char * * args , struct appctx * appctx , void * private )
{
if ( ! cli_has_level ( appctx , ACCESS_LVL_OPER ) )
return 1 ;
if ( * args [ 2 ] & & strcmp ( args [ 2 ] , " all " ) = = 0 )
appctx - > ctx . sess . target = ( void * ) - 1 ;
else if ( * args [ 2 ] )
appctx - > ctx . sess . target = ( void * ) strtoul ( args [ 2 ] , NULL , 0 ) ;
else
appctx - > ctx . sess . target = NULL ;
appctx - > ctx . sess . section = 0 ; /* start with stream status */
appctx - > ctx . sess . pos = 0 ;
return 0 ;
}
/* This function dumps all streams' states onto the stream interface's
* read buffer . It returns 0 if the output buffer is full and it needs
* to be called again , otherwise non - zero . It is designed to be called
* from stats_dump_sess_to_buffer ( ) below .
*/
static int cli_io_handler_dump_sess ( struct appctx * appctx )
{
struct stream_interface * si = appctx - > owner ;
struct connection * conn ;
if ( unlikely ( si_ic ( si ) - > flags & ( CF_WRITE_ERROR | CF_SHUTW ) ) ) {
/* If we're forced to shut down, we might have to remove our
* reference to the last stream being dumped .
*/
if ( appctx - > st2 = = STAT_ST_LIST ) {
if ( ! LIST_ISEMPTY ( & appctx - > ctx . sess . bref . users ) ) {
LIST_DEL ( & appctx - > ctx . sess . bref . users ) ;
LIST_INIT ( & appctx - > ctx . sess . bref . users ) ;
}
}
return 1 ;
}
chunk_reset ( & trash ) ;
switch ( appctx - > st2 ) {
case STAT_ST_INIT :
/* the function had not been called yet, let's prepare the
* buffer for a response . We initialize the current stream
* pointer to the first in the global list . When a target
* stream is being destroyed , it is responsible for updating
* this pointer . We know we have reached the end when this
* pointer points back to the head of the streams list .
*/
LIST_INIT ( & appctx - > ctx . sess . bref . users ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
appctx - > ctx . sess . bref . ref = streams . n ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
appctx - > st2 = STAT_ST_LIST ;
/* fall through */
case STAT_ST_LIST :
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
/* first, let's detach the back-ref from a possible previous stream */
if ( ! LIST_ISEMPTY ( & appctx - > ctx . sess . bref . users ) ) {
LIST_DEL ( & appctx - > ctx . sess . bref . users ) ;
LIST_INIT ( & appctx - > ctx . sess . bref . users ) ;
}
/* and start from where we stopped */
while ( appctx - > ctx . sess . bref . ref ! = & streams ) {
char pn [ INET6_ADDRSTRLEN ] ;
struct stream * curr_strm ;
curr_strm = LIST_ELEM ( appctx - > ctx . sess . bref . ref , struct stream * , list ) ;
if ( appctx - > ctx . sess . target ) {
if ( appctx - > ctx . sess . target ! = ( void * ) - 1 & & appctx - > ctx . sess . target ! = curr_strm )
goto next_sess ;
LIST_ADDQ ( & curr_strm - > back_refs , & appctx - > ctx . sess . bref . users ) ;
/* call the proper dump() function and return if we're missing space */
2017-06-30 10:23:45 -04:00
if ( ! stats_dump_full_strm_to_buffer ( si , curr_strm ) ) {
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
return 0 ;
2017-06-30 10:23:45 -04:00
}
2016-11-21 02:51:11 -05:00
/* stream dump complete */
LIST_DEL ( & appctx - > ctx . sess . bref . users ) ;
LIST_INIT ( & appctx - > ctx . sess . bref . users ) ;
if ( appctx - > ctx . sess . target ! = ( void * ) - 1 ) {
appctx - > ctx . sess . target = NULL ;
break ;
}
else
goto next_sess ;
}
chunk_appendf ( & trash ,
" %p: proto=%s " ,
curr_strm ,
strm_li ( curr_strm ) ? strm_li ( curr_strm ) - > proto - > name : " ? " ) ;
conn = objt_conn ( strm_orig ( curr_strm ) ) ;
switch ( conn ? addr_to_str ( & conn - > addr . from , pn , sizeof ( pn ) ) : AF_UNSPEC ) {
case AF_INET :
case AF_INET6 :
chunk_appendf ( & trash ,
" src=%s:%d fe=%s be=%s srv=%s " ,
pn ,
get_host_port ( & conn - > addr . from ) ,
strm_fe ( curr_strm ) - > id ,
( curr_strm - > be - > cap & PR_CAP_BE ) ? curr_strm - > be - > id : " <NONE> " ,
objt_server ( curr_strm - > target ) ? objt_server ( curr_strm - > target ) - > id : " <none> "
) ;
break ;
case AF_UNIX :
chunk_appendf ( & trash ,
" src=unix:%d fe=%s be=%s srv=%s " ,
strm_li ( curr_strm ) - > luid ,
strm_fe ( curr_strm ) - > id ,
( curr_strm - > be - > cap & PR_CAP_BE ) ? curr_strm - > be - > id : " <NONE> " ,
objt_server ( curr_strm - > target ) ? objt_server ( curr_strm - > target ) - > id : " <none> "
) ;
break ;
}
chunk_appendf ( & trash ,
" ts=%02x age=%s calls=%d " ,
curr_strm - > task - > state ,
human_time ( now . tv_sec - curr_strm - > logs . tv_accept . tv_sec , 1 ) ,
curr_strm - > task - > calls ) ;
chunk_appendf ( & trash ,
" rq[f=%06xh,i=%d,an=%02xh,rx=%s " ,
curr_strm - > req . flags ,
curr_strm - > req . buf - > i ,
curr_strm - > req . analysers ,
curr_strm - > req . rex ?
human_time ( TICKS_TO_MS ( curr_strm - > req . rex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
chunk_appendf ( & trash ,
" ,wx=%s " ,
curr_strm - > req . wex ?
human_time ( TICKS_TO_MS ( curr_strm - > req . wex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
chunk_appendf ( & trash ,
" ,ax=%s] " ,
curr_strm - > req . analyse_exp ?
human_time ( TICKS_TO_MS ( curr_strm - > req . analyse_exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
chunk_appendf ( & trash ,
" rp[f=%06xh,i=%d,an=%02xh,rx=%s " ,
curr_strm - > res . flags ,
curr_strm - > res . buf - > i ,
curr_strm - > res . analysers ,
curr_strm - > res . rex ?
human_time ( TICKS_TO_MS ( curr_strm - > res . rex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
chunk_appendf ( & trash ,
" ,wx=%s " ,
curr_strm - > res . wex ?
human_time ( TICKS_TO_MS ( curr_strm - > res . wex - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
chunk_appendf ( & trash ,
" ,ax=%s] " ,
curr_strm - > res . analyse_exp ?
human_time ( TICKS_TO_MS ( curr_strm - > res . analyse_exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
2017-09-13 12:30:23 -04:00
conn = cs_conn ( objt_cs ( curr_strm - > si [ 0 ] . end ) ) ;
2016-11-21 02:51:11 -05:00
chunk_appendf ( & trash ,
" s0=[%d,%1xh,fd=%d,ex=%s] " ,
curr_strm - > si [ 0 ] . state ,
curr_strm - > si [ 0 ] . flags ,
2017-08-24 08:31:19 -04:00
conn ? conn - > handle . fd : - 1 ,
2016-11-21 02:51:11 -05:00
curr_strm - > si [ 0 ] . exp ?
human_time ( TICKS_TO_MS ( curr_strm - > si [ 0 ] . exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
2017-09-13 12:30:23 -04:00
conn = cs_conn ( objt_cs ( curr_strm - > si [ 1 ] . end ) ) ;
2016-11-21 02:51:11 -05:00
chunk_appendf ( & trash ,
" s1=[%d,%1xh,fd=%d,ex=%s] " ,
curr_strm - > si [ 1 ] . state ,
curr_strm - > si [ 1 ] . flags ,
2017-08-24 08:31:19 -04:00
conn ? conn - > handle . fd : - 1 ,
2016-11-21 02:51:11 -05:00
curr_strm - > si [ 1 ] . exp ?
human_time ( TICKS_TO_MS ( curr_strm - > si [ 1 ] . exp - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
chunk_appendf ( & trash ,
" exp=%s " ,
curr_strm - > task - > expire ?
human_time ( TICKS_TO_MS ( curr_strm - > task - > expire - now_ms ) ,
TICKS_TO_MS ( 1000 ) ) : " " ) ;
if ( task_in_rq ( curr_strm - > task ) )
chunk_appendf ( & trash , " run(nice=%d) " , curr_strm - > task - > nice ) ;
chunk_appendf ( & trash , " \n " ) ;
REORG: channel: finally rename the last bi_* / bo_* functions
For HTTP/2 we'll need some buffer-only equivalent functions to some of
the ones applying to channels and still squatting the bi_* / bo_*
namespace. Since these names have kept being misleading for quite some
time now and are really getting annoying, it's time to rename them. This
commit will use "ci/co" as the prefix (for "channel in", "channel out")
instead of "bi/bo". The following ones were renamed :
bi_getblk_nc, bi_getline_nc, bi_putblk, bi_putchr,
bo_getblk, bo_getblk_nc, bo_getline, bo_getline_nc, bo_inject,
bi_putchk, bi_putstr, bo_getchr, bo_skip, bi_swpbuf
2017-10-19 08:32:15 -04:00
if ( ci_putchk ( si_ic ( si ) , & trash ) = = - 1 ) {
2016-11-21 02:51:11 -05:00
/* let's try again later from this stream. We add ourselves into
* this stream ' s users so that it can remove us upon termination .
*/
si_applet_cant_put ( si ) ;
LIST_ADDQ ( & curr_strm - > back_refs , & appctx - > ctx . sess . bref . users ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
return 0 ;
}
next_sess :
appctx - > ctx . sess . bref . ref = curr_strm - > list . n ;
}
if ( appctx - > ctx . sess . target & & appctx - > ctx . sess . target ! = ( void * ) - 1 ) {
/* specified stream not found */
if ( appctx - > ctx . sess . section > 0 )
chunk_appendf ( & trash , " *** session terminated while we were watching it *** \n " ) ;
else
chunk_appendf ( & trash , " Session not found. \n " ) ;
REORG: channel: finally rename the last bi_* / bo_* functions
For HTTP/2 we'll need some buffer-only equivalent functions to some of
the ones applying to channels and still squatting the bi_* / bo_*
namespace. Since these names have kept being misleading for quite some
time now and are really getting annoying, it's time to rename them. This
commit will use "ci/co" as the prefix (for "channel in", "channel out")
instead of "bi/bo". The following ones were renamed :
bi_getblk_nc, bi_getline_nc, bi_putblk, bi_putchr,
bo_getblk, bo_getblk_nc, bo_getline, bo_getline_nc, bo_inject,
bi_putchk, bi_putstr, bo_getchr, bo_skip, bi_swpbuf
2017-10-19 08:32:15 -04:00
if ( ci_putchk ( si_ic ( si ) , & trash ) = = - 1 ) {
2016-11-21 02:51:11 -05:00
si_applet_cant_put ( si ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
return 0 ;
}
appctx - > ctx . sess . target = NULL ;
appctx - > ctx . sess . uid = 0 ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
return 1 ;
}
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
appctx - > st2 = STAT_ST_FIN ;
/* fall through */
default :
appctx - > st2 = STAT_ST_FIN ;
return 1 ;
}
}
static void cli_release_show_sess ( struct appctx * appctx )
{
if ( appctx - > st2 = = STAT_ST_LIST ) {
2017-11-10 10:24:41 -05:00
HA_SPIN_LOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
if ( ! LIST_ISEMPTY ( & appctx - > ctx . sess . bref . users ) )
LIST_DEL ( & appctx - > ctx . sess . bref . users ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( STRMS_LOCK , & streams_lock ) ;
2016-11-21 02:51:11 -05:00
}
}
2016-11-24 05:09:25 -05:00
/* Parses the "shutdown session" directive, it always returns 1 */
static int cli_parse_shutdown_session ( char * * args , struct appctx * appctx , void * private )
{
struct stream * strm , * ptr ;
if ( ! cli_has_level ( appctx , ACCESS_LVL_ADMIN ) )
return 1 ;
if ( ! * args [ 2 ] ) {
2017-07-20 10:49:14 -04:00
appctx - > ctx . cli . severity = LOG_ERR ;
2016-11-24 05:09:25 -05:00
appctx - > ctx . cli . msg = " Session pointer expected (use 'show sess'). \n " ;
2016-11-24 09:53:53 -05:00
appctx - > st0 = CLI_ST_PRINT ;
2016-11-24 05:09:25 -05:00
return 1 ;
}
ptr = ( void * ) strtoul ( args [ 2 ] , NULL , 0 ) ;
/* first, look for the requested stream in the stream table */
list_for_each_entry ( strm , & streams , list ) {
if ( strm = = ptr )
break ;
}
/* do we have the stream ? */
if ( strm ! = ptr ) {
2017-07-20 10:49:14 -04:00
appctx - > ctx . cli . severity = LOG_ERR ;
2016-11-24 05:09:25 -05:00
appctx - > ctx . cli . msg = " No such session (use 'show sess'). \n " ;
2016-11-24 09:53:53 -05:00
appctx - > st0 = CLI_ST_PRINT ;
2016-11-24 05:09:25 -05:00
return 1 ;
}
stream_shutdown ( strm , SF_ERR_KILLED ) ;
return 1 ;
}
2016-11-23 10:50:48 -05:00
/* Parses the "shutdown session server" directive, it always returns 1 */
static int cli_parse_shutdown_sessions_server ( char * * args , struct appctx * appctx , void * private )
{
struct server * sv ;
struct stream * strm , * strm_bck ;
if ( ! cli_has_level ( appctx , ACCESS_LVL_ADMIN ) )
return 1 ;
sv = cli_find_server ( appctx , args [ 3 ] ) ;
if ( ! sv )
return 1 ;
/* kill all the stream that are on this server */
2017-11-07 04:42:54 -05:00
HA_SPIN_LOCK ( SERVER_LOCK , & sv - > lock ) ;
2016-11-23 10:50:48 -05:00
list_for_each_entry_safe ( strm , strm_bck , & sv - > actconns , by_srv )
if ( strm - > srv_conn = = sv )
stream_shutdown ( strm , SF_ERR_KILLED ) ;
2017-11-07 04:42:54 -05:00
HA_SPIN_UNLOCK ( SERVER_LOCK , & sv - > lock ) ;
2016-11-23 10:50:48 -05:00
return 1 ;
}
2016-11-21 02:51:11 -05:00
/* register cli keywords */
static struct cli_kw_list cli_kws = { { } , {
{ { " show " , " sess " , NULL } , " show sess [id] : report the list of current sessions or dump this session " , cli_parse_show_sess , cli_io_handler_dump_sess , cli_release_show_sess } ,
2016-11-24 05:09:25 -05:00
{ { " shutdown " , " session " , NULL } , " shutdown session : kill a specific session " , cli_parse_shutdown_session , NULL , NULL } ,
2016-11-23 10:50:48 -05:00
{ { " shutdown " , " sessions " , " server " } , " shutdown sessions server : kill sessions on a server " , cli_parse_shutdown_sessions_server , NULL , NULL } ,
2016-11-21 02:51:11 -05:00
{ { } , }
} } ;
2015-09-27 13:29:33 -04:00
/* main configuration keyword registration. */
static struct action_kw_list stream_tcp_keywords = { ILH , {
{ " use-service " , stream_parse_use_service } ,
{ /* END */ }
} } ;
static struct action_kw_list stream_http_keywords = { ILH , {
{ " use-service " , stream_parse_use_service } ,
{ /* END */ }
} } ;
2010-06-18 11:46:06 -04:00
__attribute__ ( ( constructor ) )
REORG/MAJOR: session: rename the "session" entity to "stream"
With HTTP/2, we'll have to support multiplexed streams. A stream is in
fact the largest part of what we currently call a session, it has buffers,
logs, etc.
In order to catch any error, this commit removes any reference to the
struct session and tries to rename most "session" occurrences in function
names to "stream" and "sess" to "strm" when that's related to a session.
The files stream.{c,h} were added and session.{c,h} removed.
The session will be reintroduced later and a few parts of the stream
will progressively be moved overthere. It will more or less contain
only what we need in an embryonic session.
Sample fetch functions and converters will have to change a bit so
that they'll use an L5 (session) instead of what's currently called
"L4" which is in fact L6 for now.
Once all changes are completed, we should see approximately this :
L7 - http_txn
L6 - stream
L5 - session
L4 - connection | applet
There will be at most one http_txn per stream, and a same session will
possibly be referenced by multiple streams. A connection will point to
a session and to a stream. The session will hold all the information
we need to keep even when we don't yet have a stream.
Some more cleanup is needed because some code was already far from
being clean. The server queue management still refers to sessions at
many places while comments talk about connections. This will have to
be cleaned up once we have a server-side connection pool manager.
Stream flags "SN_*" still need to be renamed, it doesn't seem like
any of them will need to move to the session.
2015-04-02 18:22:06 -04:00
static void __stream_init ( void )
2010-06-18 11:46:06 -04:00
{
2015-09-27 13:29:33 -04:00
tcp_req_cont_keywords_register ( & stream_tcp_keywords ) ;
http_req_keywords_register ( & stream_http_keywords ) ;
2016-11-21 02:51:11 -05:00
cli_register_kw ( & cli_kws ) ;
2010-06-18 11:46:06 -04:00
}
2006-06-25 20:48:02 -04:00
/*
* Local variables :
* c - indent - level : 8
* c - basic - offset : 8
* End :
*/