diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-25 23:53:36 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-25 23:53:36 +0000 |
commit | f7c5baf8d64cb9d477ec212c2213294afb25160d (patch) | |
tree | b47a20519636bfe39a02ec738dcf6a608c2507cc /src | |
parent | db20f07830d445c20825bac3f871bc57a5c5b5b3 (diff) | |
download | rspamd-f7c5baf8d64cb9d477ec212c2213294afb25160d.tar.gz rspamd-f7c5baf8d64cb9d477ec212c2213294afb25160d.zip |
[Minor] Another try to fix race condition in lua_redis
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_redis.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 7c5e84735..2307db835 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -355,7 +355,7 @@ lua_redis_callback (redisAsyncContext *c, gpointer r, gpointer priv) ctx = sp_ud->ctx; ud = sp_ud->c; - if (ud->terminated || sp_ud->finished) { + if (ud->terminated) { /* We are already at the termination stage, just go out */ return; } @@ -363,30 +363,34 @@ lua_redis_callback (redisAsyncContext *c, gpointer r, gpointer priv) msg_debug ("got reply from redis %p for query %p", ctx, sp_ud); REDIS_RETAIN (ctx); - ctx->cmds_pending --; - if (c->err == 0) { - if (r != NULL) { - if (reply->type != REDIS_REPLY_ERROR) { - lua_redis_push_data (reply, ctx, sp_ud); + /* If session is finished, we cannot call lua callbacks */ + if (!sp_ud->finished) { + if (c->err == 0) { + if (r != NULL) { + if (reply->type != REDIS_REPLY_ERROR) { + lua_redis_push_data (reply, ctx, sp_ud); + } + else { + lua_redis_push_error (reply->str, ctx, sp_ud, TRUE); + } } else { - lua_redis_push_error (reply->str, ctx, sp_ud, TRUE); + lua_redis_push_error ("received no data from server", ctx, sp_ud, TRUE); } } else { - lua_redis_push_error ("received no data from server", ctx, sp_ud, TRUE); - } - } - else { - if (c->err == REDIS_ERR_IO) { - lua_redis_push_error (strerror (errno), ctx, sp_ud, TRUE); - } - else { - lua_redis_push_error (c->errstr, ctx, sp_ud, TRUE); + if (c->err == REDIS_ERR_IO) { + lua_redis_push_error (strerror (errno), ctx, sp_ud, TRUE); + } + else { + lua_redis_push_error (c->errstr, ctx, sp_ud, TRUE); + } } } + ctx->cmds_pending --; + if (ctx->cmds_pending == 0 && !ud->terminated) { /* Disconnect redis early as we don't need it anymore */ ud->terminated = 1; |