if (conn->sock == -1) {
msg_err ("cannot connect upstream for %s", m->name);
- rspamd_upstream_fail (conn->up);
+ rspamd_upstream_fail (conn->up, TRUE);
return;
}
{
struct upstream *up = elt->lib_data;
- rspamd_upstream_fail (up);
+ rspamd_upstream_fail (up, FALSE);
}
static unsigned int
msg_err_redis_session ("error getting shingles: %s", c->errstr);
}
- rspamd_upstream_fail (session->up);
+ rspamd_upstream_fail (session->up, FALSE);
}
rspamd_fuzzy_redis_session_dtor (session, FALSE);
msg_err_redis_session ("error getting hashes: %s", c->errstr);
}
- rspamd_upstream_fail (session->up);
+ rspamd_upstream_fail (session->up, FALSE);
}
rspamd_fuzzy_redis_session_dtor (session, FALSE);
rspamd_inet_address_get_port (addr));
if (session->ctx == NULL) {
- rspamd_upstream_fail (up);
+ rspamd_upstream_fail (up, TRUE);
rspamd_fuzzy_redis_session_dtor (session, TRUE);
if (cb) {
msg_err_redis_session ("error getting count: %s", c->errstr);
}
- rspamd_upstream_fail (session->up);
+ rspamd_upstream_fail (session->up, FALSE);
}
rspamd_fuzzy_redis_session_dtor (session, FALSE);
rspamd_inet_address_get_port (addr));
if (session->ctx == NULL) {
- rspamd_upstream_fail (up);
+ rspamd_upstream_fail (up, TRUE);
rspamd_fuzzy_redis_session_dtor (session, TRUE);
if (cb) {
msg_err_redis_session ("error getting version: %s", c->errstr);
}
- rspamd_upstream_fail (session->up);
+ rspamd_upstream_fail (session->up, FALSE);
}
rspamd_fuzzy_redis_session_dtor (session, FALSE);
rspamd_inet_address_get_port (addr));
if (session->ctx == NULL) {
- rspamd_upstream_fail (up);
+ rspamd_upstream_fail (up, FALSE);
rspamd_fuzzy_redis_session_dtor (session, TRUE);
if (cb) {
msg_err_redis_session ("error sending update to redis: %s", c->errstr);
}
- rspamd_upstream_fail (session->up);
+ rspamd_upstream_fail (session->up, FALSE);
}
rspamd_fuzzy_redis_session_dtor (session, FALSE);
rspamd_inet_address_get_port (addr));
if (session->ctx == NULL) {
- rspamd_upstream_fail (up);
+ rspamd_upstream_fail (up, TRUE);
rspamd_fuzzy_redis_session_dtor (session, TRUE);
if (cb) {
else {
msg_err ("cannot get keys to gather stat: unknown error");
}
- rspamd_upstream_fail (cbdata->selected);
+
+ rspamd_upstream_fail (cbdata->selected, FALSE);
rspamd_redis_async_cbdata_cleanup (cbdata);
}
}
msg_err_task_check ("connection to redis server %s timed out",
rspamd_upstream_name (rt->selected));
- rspamd_upstream_fail (rt->selected);
+ rspamd_upstream_fail (rt->selected, FALSE);
if (rt->redis) {
redis = rt->redis;
else {
msg_err_task ("error getting reply from redis server %s: %s",
rspamd_upstream_name (rt->selected), c->errstr);
- rspamd_upstream_fail (rt->selected);
+ rspamd_upstream_fail (rt->selected, FALSE);
if (!rt->err) {
g_set_error (&rt->err, rspamd_redis_stat_quark (), c->err,
rspamd_upstream_name (rt->selected), c->errstr);
if (rt->redis) {
- rspamd_upstream_fail (rt->selected);
+ rspamd_upstream_fail (rt->selected, FALSE);
}
if (!rt->err) {
rspamd_upstream_name (rt->selected), c->errstr);
if (rt->redis) {
- rspamd_upstream_fail (rt->selected);
+ rspamd_upstream_fail (rt->selected, FALSE);
}
if (!rt->err) {
msg_err_task ("connection to redis server %s timed out",
rspamd_upstream_name (rt->selected));
- rspamd_upstream_fail (rt->selected);
+ rspamd_upstream_fail (rt->selected, FALSE);
if (rt->has_event) {
rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, d);
rspamd_upstream_ok (rt->selected);
}
else {
- rspamd_upstream_fail (rt->selected);
+ rspamd_upstream_fail (rt->selected, FALSE);
}
if (rt->has_event) {
rspamd_upstream_ok (rt->selected);
}
else {
- rspamd_upstream_fail (rt->selected);
+ rspamd_upstream_fail (rt->selected, FALSE);
}
if (rt->has_event) {
}
void
-rspamd_upstream_fail (struct upstream *up)
+rspamd_upstream_fail (struct upstream *up, gboolean addr_failure)
{
gdouble error_rate, max_error_rate;
gdouble sec_last, sec_cur;
}
}
- /* Also increase count of errors for this specific address */
- if (up->addrs.addr) {
- addr_elt = g_ptr_array_index (up->addrs.addr, up->addrs.cur);
- addr_elt->errors ++;
+ if (addr_failure) {
+ /* Also increase count of errors for this specific address */
+ if (up->addrs.addr) {
+ addr_elt = g_ptr_array_index (up->addrs.addr, up->addrs.cur);
+ addr_elt->errors++;
+ }
}
RSPAMD_UPSTREAM_UNLOCK (up->lock);
/**
* Add an error to an upstream
*/
-void rspamd_upstream_fail (struct upstream *up);
+void rspamd_upstream_fail (struct upstream *up, gboolean addr_failure);
/**
* Increase upstream successes count
lua_upstream_fail (lua_State *L)
{
struct upstream *up = lua_check_upstream (L);
+ gboolean fail_addr = FALSE;
if (up) {
- rspamd_upstream_fail (up);
+
+ if (lua_isboolean (L, 2)) {
+ fail_addr = lua_toboolean (L, 2);
+ }
+
+ rspamd_upstream_fail (up, fail_addr);
}
return 0;
session->state == 1 ? "read" : "write",
errno,
strerror (errno));
- rspamd_upstream_fail (session->server);
+ rspamd_upstream_fail (session->server, FALSE);
rspamd_session_remove_event (session->task->s, fuzzy_io_fin, session);
}
else {
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (session->addr),
session->retransmits);
- rspamd_upstream_fail (session->server);
+ rspamd_upstream_fail (session->server, FALSE);
rspamd_session_remove_event (session->task->s, fuzzy_io_fin, session);
}
else {
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (session->addr),
errno, strerror (errno));
- rspamd_upstream_fail (session->server);
+ rspamd_upstream_fail (session->server, FALSE);
}
/*
task = session->task;
if (session->retransmits >= fuzzy_module_ctx->retransmits) {
- rspamd_upstream_fail (session->server);
+ rspamd_upstream_fail (session->server, FALSE);
msg_err_task_check ("got IO timeout with server %s(%s), "
"after %d retransmits",
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (addr),
errno,
strerror (errno));
- rspamd_upstream_fail (selected);
+ rspamd_upstream_fail (selected, FALSE);
g_ptr_array_free (commands, TRUE);
}
else {
if ((sock = rspamd_inet_address_connect (addr,
SOCK_DGRAM, TRUE)) == -1) {
- rspamd_upstream_fail (selected);
+ rspamd_upstream_fail (selected, TRUE);
}
else {
s =
if ((sock = rspamd_inet_address_connect (addr,
SOCK_DGRAM, TRUE)) == -1) {
- rspamd_upstream_fail (selected);
+ rspamd_upstream_fail (selected, TRUE);
}
else {
s =
msg_err_surbl ("connection with http server %s terminated incorrectly: %e",
rspamd_inet_address_to_string (rspamd_upstream_addr (param->redirector)),
err);
- rspamd_upstream_fail (param->redirector);
+ rspamd_upstream_fail (param->redirector, FALSE);
rspamd_session_remove_event (param->task->s, free_redirector_session,
param);
}
bk_conn->err = rspamd_mempool_strdup (session->pool, err->message);
}
- rspamd_upstream_fail (bk_conn->up);
+ rspamd_upstream_fail (bk_conn->up, FALSE);
proxy_backend_close_connection (bk_conn);
REF_RELEASE (bk_conn->s);
if (bk_conn->backend_sock == -1) {
msg_err_session ("cannot connect upstream for %s", m->name);
- rspamd_upstream_fail (bk_conn->up);
+ rspamd_upstream_fail (bk_conn->up, TRUE);
continue;
}
err,
session->ctx->max_retries - session->retries);
session->retries ++;
- rspamd_upstream_fail (bk_conn->up);
+ rspamd_upstream_fail (bk_conn->up, FALSE);
proxy_backend_close_connection (session->master_conn);
if (session->ctx->max_retries &&
host ? hostbuf : "default",
rspamd_inet_address_to_string (rspamd_upstream_addr (
session->master_conn->up)));
- rspamd_upstream_fail (session->master_conn->up);
+ rspamd_upstream_fail (session->master_conn->up, TRUE);
session->retries ++;
goto retry;
}
next_addr = rspamd_upstream_addr (up);
g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET6);
/* Test errors with IPv6 */
- rspamd_upstream_fail (up);
+ rspamd_upstream_fail (up, TRUE);
/* Now we should have merely IPv4 addresses in rotation */
addr = rspamd_upstream_addr (up);
for (i = 0; i < 256; i++) {
up = rspamd_upstream_get (ls, RSPAMD_UPSTREAM_MASTER_SLAVE, NULL, 0);
for (i = 0; i < 100; i ++) {
- rspamd_upstream_fail (up);
+ rspamd_upstream_fail (up, TRUE);
}
g_assert (rspamd_upstreams_alive (ls) == 2);