struct upstream *selected;
struct event timeout_event;
redisAsyncContext *redis;
+ gboolean has_event;
};
static GQuark
rspamd_redis_cache_fin (gpointer data)
{
struct rspamd_redis_cache_runtime *rt = data;
+ redisAsyncContext *redis;
+
+ rt->has_event = FALSE;
+ if (event_get_base (&rt->timeout_event)) {
+ event_del (&rt->timeout_event);
+ }
- event_del (&rt->timeout_event);
- redisAsyncFree (rt->redis);
+ if (rt->redis) {
+ redis = rt->redis;
+ rt->redis = NULL;
+ /* This calls for all callbacks pending */
+ redisAsyncFree (redis);
+ }
}
static void
msg_err_task ("connection to redis server %s timed out",
rspamd_upstream_name (rt->selected));
rspamd_upstream_fail (rt->selected);
- rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, d);
+
+ if (rt->has_event) {
+ rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, d);
+ }
}
/* Called when we have checked the specified message id */
task = rt->task;
if (c->err == 0) {
- if (G_LIKELY (reply->type == REDIS_REPLY_INTEGER)) {
- val = reply->integer;
- }
- else if (reply->type == REDIS_REPLY_STRING) {
- rspamd_strtol (reply->str, reply->len, &val);
- }
- else {
- if (reply->type != REDIS_REPLY_NIL) {
- msg_err_task ("bad learned type for %s: %d",
- rt->ctx->stcf->symbol, reply->type);
+ if (reply) {
+ if (G_LIKELY (reply->type == REDIS_REPLY_INTEGER)) {
+ val = reply->integer;
+ }
+ else if (reply->type == REDIS_REPLY_STRING) {
+ rspamd_strtol (reply->str, reply->len, &val);
}
+ else {
+ if (reply->type != REDIS_REPLY_NIL) {
+ msg_err_task ("bad learned type for %s: %d",
+ rt->ctx->stcf->symbol, reply->type);
+ }
- val = 0;
+ val = 0;
+ }
}
if ((val > 0 && (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM)) ||
rspamd_upstream_fail (rt->selected);
}
- rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, rt);
+ if (rt->has_event) {
+ rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, rt);
+ }
}
/* Called when we have learned the specified message id */
rspamd_upstream_fail (rt->selected);
}
- rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, rt);
+ if (rt->has_event) {
+ rspamd_session_remove_event (task->s, rspamd_redis_cache_fin, rt);
+ }
}
static void
rspamd_session_add_event (task->s, rspamd_redis_cache_fin, rt,
rspamd_stat_cache_redis_quark ());
event_add (&rt->timeout_event, &tv);
+ rt->has_event = TRUE;
}
/* We need to return OK every time */
rspamd_session_add_event (task->s, rspamd_redis_cache_fin, rt,
rspamd_stat_cache_redis_quark ());
event_add (&rt->timeout_event, &tv);
+ rt->has_event = TRUE;
}
/* We need to return OK every time */