if (ud->ctx) {
LL_FOREACH_SAFE (ud->specific, cur, tmp) {
- event_del (&cur->timeout);
+ if (rspamd_event_pending (&cur->timeout, EV_TIMEOUT)) {
+ event_del (&cur->timeout);
+ }
if (!(cur->flags & LUA_REDIS_SPECIFIC_REPLIED)) {
is_successful = FALSE;
struct lua_redis_ctx *ctx;
ctx = sp_ud->ctx;
- event_del (&sp_ud->timeout);
+
+ if (rspamd_event_pending (&sp_ud->timeout, EV_TIMEOUT)) {
+ event_del (&sp_ud->timeout);
+ }
+
msg_debug ("finished redis query %p from session %p", sp_ud, ctx);
sp_ud->flags |= LUA_REDIS_SPECIFIC_FINISHED;
return;
}
- msg_debug ("got reply from redis %p for query %p", ctx, sp_ud);
+ msg_debug ("got reply from redis %p for query %p", sp_ud->c->ctx, sp_ud);
REDIS_RETAIN (ctx);
return;
}
- event_del (&sp_ud->timeout);
+ if (rspamd_event_pending (&sp_ud->timeout, EV_TIMEOUT)) {
+ event_del (&sp_ud->timeout);
+ }
- msg_debug ("got reply from redis %p for query %p", ctx, sp_ud);
+ msg_debug ("got reply from redis: %p for query %p", ac, sp_ud);
struct lua_redis_result *result = g_malloc0 (sizeof *result);
/* if error happened, we should terminate the connection,
and release it */
- if (result->is_error) {
+ if (result->is_error && sp_ud->c->ctx) {
+ ac = sp_ud->c->ctx;
/* Set to NULL to avoid double free in dtor */
sp_ud->c->ctx = NULL;
ctx->flags |= LUA_REDIS_TERMINATED;
ctx->thread = NULL;
results = lua_redis_push_results (ctx, thread->lua_state);
-
lua_thread_resume (thread, results);
-
lua_redis_cleanup_events (ctx);
}
}
struct lua_redis_ctx *ctx = sp_ud->ctx;
redisAsyncContext *ac;
- ac = sp_ud->c->ctx;
+ msg_debug ("timeout while querying redis server: %p, redis: %p", sp_ud,
+ sp_ud->c->ctx);
- /* Set to NULL to avoid double free in dtor */
- sp_ud->c->ctx = NULL;
- ac->err = REDIS_ERR_IO;
- errno = ETIMEDOUT;
- ctx->flags |= LUA_REDIS_TERMINATED;
+ if (sp_ud->c->ctx) {
+ ac = sp_ud->c->ctx;
+
+ /* Set to NULL to avoid double free in dtor */
+ sp_ud->c->ctx = NULL;
+ ac->err = REDIS_ERR_IO;
+ errno = ETIMEDOUT;
+ ctx->flags |= LUA_REDIS_TERMINATED;
- /*
- * This will call all callbacks pending so the entire context
- * will be destructed
- */
- rspamd_redis_pool_release_connection (sp_ud->c->pool, ac, TRUE);
+ /*
+ * This will call all callbacks pending so the entire context
+ * will be destructed
+ */
+ rspamd_redis_pool_release_connection (sp_ud->c->pool, ac, TRUE);
+ }
}
static void
ctx = sp_ud->ctx;
REDIS_RETAIN (ctx);
- msg_debug ("timeout while querying redis server");
+ msg_debug ("timeout while querying redis server: %p, redis: %p", sp_ud,
+ sp_ud->c->ctx);
lua_redis_push_error ("timeout while connecting the server", ctx, sp_ud, TRUE);
if (sp_ud->c->ctx) {
ctx = rspamd_lua_redis_prepare_connection (L, NULL, FALSE);
-
if (ctx) {
-
- lua_pushstring (L, "timeout");
- lua_gettable (L, -2);
- if (lua_type (L, -1) == LUA_TNUMBER) {
- timeout = lua_tonumber (L, -1);
+ if (lua_istable (L, 1)) {
+ lua_pushstring (L, "timeout");
+ lua_gettable (L, 1);
+ if (lua_type (L, -1) == LUA_TNUMBER) {
+ timeout = lua_tonumber (L, -1);
+ }
+ lua_pop (L, 1);
}
- lua_pop (L, 1);
ctx->async.timeout = timeout;