summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlake Matheny <bmatheny@mobocracy.net>2011-05-24 11:46:19 -0400
committerBlake Matheny <bmatheny@mobocracy.net>2011-05-24 11:46:19 -0400
commit72688572548655cbd16178ae096f5d4b73ed03dc (patch)
treec51865a4444ead6bd5a72455568e3c25cfcbdfa1
parent82ad944412419c6ae946f11e7d9760a584c1c1cd (diff)
Fix the case where an error reply is received before any callbacks are registered
-rw-r--r--async.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/async.c b/async.c
index 4dc6a47..b085096 100644
--- a/async.c
+++ b/async.c
@@ -361,7 +361,17 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
/* Even if the context is subscribed, pending regular callbacks will
* get a reply before pub/sub messages arrive. */
if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) {
- /* No more regular callbacks, the context *must* be subscribed. */
+ // error reply before any callbacks were setup
+ if ( ((redisReply*)reply)->type == REDIS_REPLY_ERROR ) {
+ c->err = REDIS_ERR_OTHER;
+ err_len = strlen(((redisReply*)reply)->str);
+ err_len = err_len < (sizeof(c->errstr)-1) ? err_len : (sizeof(c->errstr)-1);
+ memcpy(c->errstr, ((redisReply*)reply)->str, err_len);
+ c->errstr[err_len] = '\0';
+ __redisAsyncDisconnect(ac);
+ return;
+ }
+ /* No more regular callbacks and no errors, the context *must* be subscribed. */
assert(c->flags & REDIS_SUBSCRIBED);
__redisGetSubscribeCallback(ac,reply,&cb);
}