Browse Source

Locked redis context on redis notification

pull/225/head
Frederic-Philippe Metz 10 years ago
parent
commit
637d1f4cce
1 changed files with 11 additions and 7 deletions
  1. +11
    -7
      daemon/redis.c

+ 11
- 7
daemon/redis.c View File

@ -231,24 +231,26 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
return; return;
} }
mutex_lock(&r->lock);
r = cm->conf.redis_read_notify; r = cm->conf.redis_read_notify;
redisReply *rr = (redisReply*)reply; redisReply *rr = (redisReply*)reply;
if (reply == NULL || rr->type != REDIS_REPLY_ARRAY) if (reply == NULL || rr->type != REDIS_REPLY_ARRAY)
return;
goto err;
for (int j = 0; j < rr->elements; j++) { for (int j = 0; j < rr->elements; j++) {
rlog(LOG_INFO, "Redis-Notify: %u) %s\n", j, rr->element[j]->str); rlog(LOG_INFO, "Redis-Notify: %u) %s\n", j, rr->element[j]->str);
} }
if (rr->elements != 4) if (rr->elements != 4)
return;
goto err;
char *pch = strstr(rr->element[2]->str, "notifier-"); char *pch = strstr(rr->element[2]->str, "notifier-");
if (pch == NULL) { if (pch == NULL) {
rlog(LOG_ERROR,"Redis-Notifier: The substring 'notifier-' has not been found in the redis notification !\n"); rlog(LOG_ERROR,"Redis-Notifier: The substring 'notifier-' has not been found in the redis notification !\n");
return;
goto err;
} }
@ -260,7 +262,7 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
++pdbstr; ++p; ++pdbstr; ++p;
if (pdbstr-db_str>15) { if (pdbstr-db_str>15) {
rlog(LOG_ERROR, "Could not extract keyspace db from notification."); rlog(LOG_ERROR, "Could not extract keyspace db from notification.");
return;
goto err;
} }
} }
dbno = r->db = atoi(db_str); dbno = r->db = atoi(db_str);
@ -271,7 +273,7 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
rlog(LOG_ERR, "Redis error: %s", r->ctx->errstr); rlog(LOG_ERR, "Redis error: %s", r->ctx->errstr);
redisFree(r->ctx); redisFree(r->ctx);
r->ctx = NULL; r->ctx = NULL;
return;
goto err;
} }
pch += strlen("notifier-"); pch += strlen("notifier-");
@ -285,13 +287,13 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
if (c && c->redis_call_responsible) { if (c && c->redis_call_responsible) {
rlog(LOG_DEBUG,"I am responsible for that call so I ignore redis notifications."); rlog(LOG_DEBUG,"I am responsible for that call so I ignore redis notifications.");
return;
goto err;
} }
if (strncmp(rr->element[3]->str,"sadd",4)==0) { if (strncmp(rr->element[3]->str,"sadd",4)==0) {
if (c) { if (c) {
rlog(LOG_INFO, "Redis-Notifier: Call already exists with this callid:%s\n", rr->element[2]->str); rlog(LOG_INFO, "Redis-Notifier: Call already exists with this callid:%s\n", rr->element[2]->str);
return;
goto err;
} }
redis_restore_call(r, cm, rr->element[2]); redis_restore_call(r, cm, rr->element[2]);
@ -306,6 +308,8 @@ void onRedisNotification(redisAsyncContext *actx, void *reply, void *privdata) {
call_destroy(c); call_destroy(c);
} }
err:
mutex_unlock(&r->lock);
} }
void redis_notify_event_base_loopbreak(struct callmaster *cm) { void redis_notify_event_base_loopbreak(struct callmaster *cm) {


Loading…
Cancel
Save