Skip to content

Commit 601b34f

Browse files
committed
MINOR: connection: add new sample fetch functions fc_err_name and bc_err_name
These functions return a symbolic error code such as ECONNRESET to keep logs compact while making them human-readable. It's a good alternative to the numeric code in that it's more expressive, and a good one to the full message since it's shorter and more precise (some codes even match errno names). The doc was updated so that the symbolic names appear in the table. It could be useful to backport this feature to help with troubleshooting some issues, though backporting the doc might possibly be more annoying in case users have local patches already, so maybe the table update does not need to be backported in this case.
1 parent 822d82c commit 601b34f

File tree

3 files changed

+149
-63
lines changed

3 files changed

+149
-63
lines changed

doc/configuration.txt

Lines changed: 75 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22234,6 +22234,7 @@ bc_be_queue integer
2223422234
bc_dst ip
2223522235
bc_dst_port integer
2223622236
bc_err integer
22237+
bc_err_name string
2223722238
bc_err_str string
2223822239
bc_glitches integer
2223922240
bc_http_major integer
@@ -22263,6 +22264,7 @@ fc_dst ip
2226322264
fc_dst_is_local boolean
2226422265
fc_dst_port integer
2226522266
fc_err integer
22267+
fc_err_name string
2226622268
fc_err_str string
2226722269
fc_fackets integer
2226822270
fc_glitches integer
@@ -22491,6 +22493,12 @@ bc_err : integer
2249122493
connection. See the "fc_err_str" fetch for a full list of error codes
2249222494
and their corresponding error message.
2249322495

22496+
bc_err_name : string
22497+
Returns the internal error name describing what problem happened on the
22498+
backend connection, resulting in a connection failure. This string is made of
22499+
a single word and is empty when no error is present. It corresponds to the
22500+
"name" column in the table presented in the "fc_err_str" keyword.
22501+
2249422502
bc_err_str : string
2249522503
Returns an error message describing what problem happened on the current
2249622504
backend connection, resulting in a connection failure. See the
@@ -22673,73 +22681,79 @@ fc_err : integer
2267322681
described in section 8.2.5). See the "fc_err_str" fetch for a full list of
2267422682
error codes and their corresponding error message.
2267522683

22684+
fc_err_name : string
22685+
Returns the internal error name describing what problem happened on the
22686+
frontend connection, resulting in a connection failure. This string is made
22687+
of a single word and is empty when no error is present. It corresponds to the
22688+
"name" column in the table presented in the "fc_err_str" keyword.
22689+
2267622690
fc_err_str : string
2267722691
Returns an error message describing what problem happened on the current
2267822692
connection, resulting in a connection failure. This string corresponds to the
2267922693
"message" part of the error log format (see section 8.2.5). See below for a
2268022694
full list of error codes and their corresponding error messages :
2268122695

22682-
+----+---------------------------------------------------------------------------+
22683-
| ID | message |
22684-
+----+---------------------------------------------------------------------------+
22685-
| 0 | "Success" |
22686-
| 1 | "Reached configured maxconn value" |
22687-
| 2 | "Too many sockets on the process" |
22688-
| 3 | "Too many sockets on the system" |
22689-
| 4 | "Out of system buffers" |
22690-
| 5 | "Protocol or address family not supported" |
22691-
| 6 | "General socket error" |
22692-
| 7 | "Source port range exhausted" |
22693-
| 8 | "Can't bind to source address" |
22694-
| 9 | "Out of local source ports on the system" |
22695-
| 10 | "Local source address already in use" |
22696-
| 11 | "Connection closed while waiting for PROXY protocol header" |
22697-
| 12 | "Connection error while waiting for PROXY protocol header" |
22698-
| 13 | "Timeout while waiting for PROXY protocol header" |
22699-
| 14 | "Truncated PROXY protocol header received" |
22700-
| 15 | "Received something which does not look like a PROXY protocol header" |
22701-
| 16 | "Received an invalid PROXY protocol header" |
22702-
| 17 | "Received an unhandled protocol in the PROXY protocol header" |
22703-
| 18 | "Connection closed while waiting for NetScaler Client IP header" |
22704-
| 19 | "Connection error while waiting for NetScaler Client IP header" |
22705-
| 20 | "Timeout while waiting for a NetScaler Client IP header" |
22706-
| 21 | "Truncated NetScaler Client IP header received" |
22707-
| 22 | "Received an invalid NetScaler Client IP magic number" |
22708-
| 23 | "Received an unhandled protocol in the NetScaler Client IP header" |
22709-
| 24 | "Connection closed during SSL handshake" |
22710-
| 25 | "Connection error during SSL handshake" |
22711-
| 26 | "Timeout during SSL handshake" |
22712-
| 27 | "Too many SSL connections" |
22713-
| 28 | "Out of memory when initializing an SSL connection" |
22714-
| 29 | "Rejected a client-initiated SSL renegotiation attempt" |
22715-
| 30 | "SSL client CA chain cannot be verified" |
22716-
| 31 | "SSL client certificate not trusted" |
22717-
| 32 | "Server presented an SSL certificate different from the configured one" |
22718-
| 33 | "Server presented an SSL certificate different from the expected one" |
22719-
| 34 | "SSL handshake failure" |
22720-
| 35 | "SSL handshake failure after heartbeat" |
22721-
| 36 | "Stopped a TLSv1 heartbeat attack (CVE-2014-0160)" |
22722-
| 37 | "Attempt to use SSL on an unknown target (internal error)" |
22723-
| 38 | "Server refused early data" |
22724-
| 39 | "SOCKS4 Proxy write error during handshake" |
22725-
| 40 | "SOCKS4 Proxy read error during handshake" |
22726-
| 41 | "SOCKS4 Proxy deny the request" |
22727-
| 42 | "SOCKS4 Proxy handshake aborted by server" |
22728-
| 43 | "SSL fatal error" |
22729-
| 44 | "Reverse connect failure" |
22730-
| 45 | "Poller reported POLLERR" |
22731-
| 46 | "ECONNREFUSED returned by OS" |
22732-
| 47 | "ECONNRESET returned by OS" |
22733-
| 48 | "ENETUNREACH returned by OS" |
22734-
| 49 | "ENOMEM returned by OS" |
22735-
| 50 | "EBADF returned by OS" |
22736-
| 51 | "EFAULT returned by OS" |
22737-
| 52 | "EINVAL returned by OS" |
22738-
| 53 | "ENCONN returned by OS" |
22739-
| 54 | "ENSOCK returned by OS" |
22740-
| 55 | "ENOBUFS returned by OS" |
22741-
| 56 | "EPIPE returned by OS" |
22742-
+----+---------------------------------------------------------------------------+
22696+
+----+------------------+-------------------------------------------------------------------------+
22697+
| ID | name | message |
22698+
+----+------------------+-------------------------------------------------------------------------+
22699+
| 0 | - | "Success" |
22700+
| 1 | CONF_FDLIM | "Reached configured maxconn value" |
22701+
| 2 | PROC_FDLIM | "Too many sockets on the process" |
22702+
| 3 | SYS_FDLIM | "Too many sockets on the system" |
22703+
| 4 | SYS_MEMLIM | "Out of system buffers" |
22704+
| 5 | NOPROTO | "Protocol or address family not supported" |
22705+
| 6 | SOCK_ERR | "General socket error" |
22706+
| 7 | PORT_RANGE | "Source port range exhausted" |
22707+
| 8 | CANT_BIND | "Can't bind to source address" |
22708+
| 9 | FREE_PORTS | "Out of local source ports on the system" |
22709+
| 10 | ADDR_INUSE | "Local source address already in use" |
22710+
| 11 | PRX_EMPTY | "Connection closed while waiting for PROXY protocol header" |
22711+
| 12 | PRX_ABORT | "Connection error while waiting for PROXY protocol header" |
22712+
| 13 | PRX_TIMEOUT | "Timeout while waiting for PROXY protocol header" |
22713+
| 14 | PRX_TRUNCATED | "Truncated PROXY protocol header received" |
22714+
| 15 | PRX_NOT_HDR | "Received something which does not look like a PROXY protocol header" |
22715+
| 16 | PRX_BAD_HDR | "Received an invalid PROXY protocol header" |
22716+
| 17 | PRX_BAD_PROTO | "Received an unhandled protocol in the PROXY protocol header" |
22717+
| 18 | CIP_EMPTY | "Connection closed while waiting for NetScaler Client IP header" |
22718+
| 19 | CIP_ABORT | "Connection error while waiting for NetScaler Client IP header" |
22719+
| 20 | CIP_TIMEOUT | "Timeout while waiting for a NetScaler Client IP header" |
22720+
| 21 | CIP_TRUNCATED | "Truncated NetScaler Client IP header received" |
22721+
| 22 | CIP_BAD_MAGIC | "Received an invalid NetScaler Client IP magic number" |
22722+
| 23 | CIP_BAD_PROTO | "Received an unhandled protocol in the NetScaler Client IP header" |
22723+
| 24 | SSL_EMPTY | "Connection closed during SSL handshake" |
22724+
| 25 | SSL_ABORT | "Connection error during SSL handshake" |
22725+
| 26 | SSL_TIMEOUT | "Timeout during SSL handshake" |
22726+
| 27 | SSL_TOO_MANY | "Too many SSL connections" |
22727+
| 28 | SSL_NO_MEM | "Out of memory when initializing an SSL connection" |
22728+
| 29 | SSL_RENEG | "Rejected a client-initiated SSL renegotiation attempt" |
22729+
| 30 | SSL_CA_FAIL | "SSL client CA chain cannot be verified" |
22730+
| 31 | SSL_CRT_FAIL | "SSL client certificate not trusted" |
22731+
| 32 | SSL_MISMATCH | "Server presented an SSL certificate different from the configured one" |
22732+
| 33 | SSL_MISMATCH_SNI | "Server presented an SSL certificate different from the expected one" |
22733+
| 34 | SSL_HANDSHAKE | "SSL handshake failure" |
22734+
| 35 | SSL_HANDSHAKE_HB | "SSL handshake failure after heartbeat" |
22735+
| 36 | SSL_KILLED_HB | "Stopped a TLSv1 heartbeat attack (CVE-2014-0160)" |
22736+
| 37 | SSL_NO_TARGET | "Attempt to use SSL on an unknown target (internal error)" |
22737+
| 38 | SSL_EARLY_FAILED | "Server refused early data" |
22738+
| 39 | SOCKS4_SEND | "SOCKS4 Proxy write error during handshake" |
22739+
| 40 | SOCKS4_RECV | "SOCKS4 Proxy read error during handshake" |
22740+
| 41 | SOCKS4_DENY | "SOCKS4 Proxy deny the request" |
22741+
| 42 | SOCKS4_ABORT | "SOCKS4 Proxy handshake aborted by server" |
22742+
| 43 | SSL_FATAL | "SSL fatal error" |
22743+
| 44 | REVERSE | "Reverse connect failure" |
22744+
| 45 | POLLERR | "Poller reported POLLERR" |
22745+
| 46 | EREFUSED | "ECONNREFUSED returned by OS" |
22746+
| 47 | ERESET | "ECONNRESET returned by OS" |
22747+
| 48 | EUNREACH | "ENETUNREACH returned by OS" |
22748+
| 49 | ENOMEM | "ENOMEM returned by OS" |
22749+
| 50 | EBADF | "EBADF returned by OS" |
22750+
| 51 | EFAULT | "EFAULT returned by OS" |
22751+
| 52 | EINVAL | "EINVAL returned by OS" |
22752+
| 53 | ENCONN | "ENCONN returned by OS" |
22753+
| 54 | ENSOCK | "ENSOCK returned by OS" |
22754+
| 55 | ENOBUFS | "ENOBUFS returned by OS" |
22755+
| 56 | EPIPE | "EPIPE returned by OS" |
22756+
+----+------------------+-------------------------------------------------------------------------+
2274322757

2274422758
fc_fackets : integer
2274522759
Returns the fack counter measured by the kernel for the client

include/haproxy/connection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ uint64_t conn_hash_prehash(const char *buf, size_t size);
102102

103103
int conn_reverse(struct connection *conn);
104104

105+
const char *conn_err_code_name(struct connection *c);
105106
const char *conn_err_code_str(struct connection *c);
106107
int xprt_add_hs(struct connection *conn);
107108
void register_mux_proto(struct mux_proto_list *list);

src/connection.c

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,74 @@ int xprt_add_hs(struct connection *conn)
686686
return 0;
687687
}
688688

689+
/* returns a short name for an error, typically the same as the enum name
690+
* without the "CO_ER_" prefix, or an empty string for no error (better eye
691+
* catching in logs). This is more compact for some debug cases.
692+
*/
693+
const char *conn_err_code_name(struct connection *c)
694+
{
695+
switch (c->err_code) {
696+
case CO_ER_NONE: return "";
697+
case CO_ER_CONF_FDLIM: return "CONF_FDLIM";
698+
case CO_ER_PROC_FDLIM: return "PROC_FDLIM";
699+
case CO_ER_SYS_FDLIM: return "SYS_FDLIM";
700+
case CO_ER_SYS_MEMLIM: return "SYS_MEMLIM";
701+
case CO_ER_NOPROTO: return "NOPROTO";
702+
case CO_ER_SOCK_ERR: return "SOCK_ERR";
703+
case CO_ER_PORT_RANGE: return "PORT_RANGE";
704+
case CO_ER_CANT_BIND: return "CANT_BIND";
705+
case CO_ER_FREE_PORTS: return "FREE_PORTS";
706+
case CO_ER_ADDR_INUSE: return "ADDR_INUSE";
707+
case CO_ER_PRX_EMPTY: return "PRX_EMPTY";
708+
case CO_ER_PRX_ABORT: return "PRX_ABORT";
709+
case CO_ER_PRX_TIMEOUT: return "PRX_TIMEOUT";
710+
case CO_ER_PRX_TRUNCATED: return "PRX_TRUNCATED";
711+
case CO_ER_PRX_NOT_HDR: return "PRX_NOT_HDR";
712+
case CO_ER_PRX_BAD_HDR: return "PRX_BAD_HDR";
713+
case CO_ER_PRX_BAD_PROTO: return "PRX_BAD_PROTO";
714+
case CO_ER_CIP_EMPTY: return "CIP_EMPTY";
715+
case CO_ER_CIP_ABORT: return "CIP_ABORT";
716+
case CO_ER_CIP_TIMEOUT: return "CIP_TIMEOUT";
717+
case CO_ER_CIP_TRUNCATED: return "CIP_TRUNCATED";
718+
case CO_ER_CIP_BAD_MAGIC: return "CIP_BAD_MAGIC";
719+
case CO_ER_CIP_BAD_PROTO: return "CIP_BAD_PROTO";
720+
case CO_ER_SSL_EMPTY: return "SSL_EMPTY";
721+
case CO_ER_SSL_ABORT: return "SSL_ABORT";
722+
case CO_ER_SSL_TIMEOUT: return "SSL_TIMEOUT";
723+
case CO_ER_SSL_TOO_MANY: return "SSL_TOO_MANY";
724+
case CO_ER_SSL_NO_MEM: return "SSL_NO_MEM";
725+
case CO_ER_SSL_RENEG: return "SSL_RENEG";
726+
case CO_ER_SSL_CA_FAIL: return "SSL_CA_FAIL";
727+
case CO_ER_SSL_CRT_FAIL: return "SSL_CRT_FAIL";
728+
case CO_ER_SSL_MISMATCH: return "SSL_MISMATCH";
729+
case CO_ER_SSL_MISMATCH_SNI: return "SSL_MISMATCH_SNI";
730+
case CO_ER_SSL_HANDSHAKE: return "SSL_HANDSHAKE";
731+
case CO_ER_SSL_HANDSHAKE_HB: return "SSL_HANDSHAKE_HB";
732+
case CO_ER_SSL_KILLED_HB: return "SSL_KILLED_HB";
733+
case CO_ER_SSL_NO_TARGET: return "SSL_NO_TARGET";
734+
case CO_ER_SSL_EARLY_FAILED: return "SSL_EARLY_FAILED";
735+
case CO_ER_SOCKS4_SEND: return "SOCKS4_SEND";
736+
case CO_ER_SOCKS4_RECV: return "SOCKS4_RECV";
737+
case CO_ER_SOCKS4_DENY: return "SOCKS4_DENY";
738+
case CO_ER_SOCKS4_ABORT: return "SOCKS4_ABORT";
739+
case CO_ER_SSL_FATAL: return "SSL_FATAL";
740+
case CO_ER_REVERSE: return "REVERSE";
741+
case CO_ER_POLLERR: return "POLLERR";
742+
case CO_ER_EREFUSED: return "EREFUSED";
743+
case CO_ER_ERESET: return "ERESET";
744+
case CO_ER_EUNREACH: return "EUNREACH";
745+
case CO_ER_ENOMEM: return "ENOMEM";
746+
case CO_ER_EBADF: return "EBADF";
747+
case CO_ER_EFAULT: return "EFAULT";
748+
case CO_ER_EINVAL: return "EINVAL";
749+
case CO_ER_ENCONN: return "ENCONN";
750+
case CO_ER_ENSOCK: return "ENSOCK";
751+
case CO_ER_ENOBUFS: return "ENOBUFS";
752+
case CO_ER_EPIPE: return "EPIPE";
753+
}
754+
return NULL;
755+
}
756+
689757
/* returns a human-readable error code for conn->err_code, or NULL if the code
690758
* is unknown.
691759
*/
@@ -2530,7 +2598,7 @@ int smp_fetch_fc_err(const struct arg *args, struct sample *smp, const char *kw,
25302598
return 1;
25312599
}
25322600

2533-
/* fetch a string representation of the error code of a connection */
2601+
/* fetch a string representation of the error code of a connection ({fc,bc}_err_{str,name} */
25342602
int smp_fetch_fc_err_str(const struct arg *args, struct sample *smp, const char *kw, void *private)
25352603
{
25362604
struct connection *conn;
@@ -2550,7 +2618,8 @@ int smp_fetch_fc_err_str(const struct arg *args, struct sample *smp, const char
25502618
return 0;
25512619
}
25522620

2553-
err_code_str = conn_err_code_str(conn);
2621+
/* [7] = "str" or "name" */
2622+
err_code_str = kw[7] == 's' ? conn_err_code_str(conn) : conn_err_code_name(conn);
25542623

25552624
if (!err_code_str)
25562625
return 0;
@@ -2623,12 +2692,14 @@ int smp_fetch_fc_streams_limit(const struct arg *args, struct sample *smp, const
26232692
*/
26242693
static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
26252694
{ "bc_err", smp_fetch_fc_err, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV },
2695+
{ "bc_err_name", smp_fetch_fc_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4SRV },
26262696
{ "bc_err_str", smp_fetch_fc_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4SRV },
26272697
{ "bc_glitches", smp_fetch_fc_glitches, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV },
26282698
{ "bc_http_major", smp_fetch_fc_http_major, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV },
26292699
{ "bc_nb_streams", smp_fetch_fc_nb_streams, 0, NULL, SMP_T_SINT, SMP_USE_L5SRV },
26302700
{ "bc_setting_streams_limit", smp_fetch_fc_streams_limit, 0, NULL, SMP_T_SINT, SMP_USE_L5SRV },
26312701
{ "fc_err", smp_fetch_fc_err, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },
2702+
{ "fc_err_name", smp_fetch_fc_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4CLI },
26322703
{ "fc_err_str", smp_fetch_fc_err_str, 0, NULL, SMP_T_STR, SMP_USE_L4CLI },
26332704
{ "fc_glitches", smp_fetch_fc_glitches, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },
26342705
{ "fc_http_major", smp_fetch_fc_http_major, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },

0 commit comments

Comments
 (0)