Added asynchronous reconnect, fixed memory leak.

master
Nicolas Favre-Felix 14 years ago
parent a91b7b13e1
commit 513982d8de

@ -168,6 +168,7 @@ cmd_run(struct worker *w, struct http_client *client,
/* check that the client is able to run this command */
if(!acl_allow_command(cmd, w->s->cfg, client)) {
cmd_free(cmd);
return CMD_ACL_FAIL;
}
@ -182,6 +183,7 @@ cmd_run(struct worker *w, struct http_client *client,
/* no args (e.g. INFO command) */
if(!slash) {
if(!ac) {
cmd_free(cmd);
return CMD_REDIS_UNAVAIL;
}
redisAsyncCommandArgv(ac, f_format, cmd, 1,
@ -219,6 +221,7 @@ cmd_run(struct worker *w, struct http_client *client,
return CMD_SENT;
}
/* failed to find a suitable connection to Redis. */
cmd_free(cmd);
return CMD_REDIS_UNAVAIL;
}

@ -44,6 +44,8 @@ format_send_error(struct cmd *cmd, short code, const char *msg) {
http_response_set_header(&resp, "Connection", "Close");
}
http_response_write(&resp, cmd->fd);
cmd_free(cmd);
}
void

@ -40,6 +40,41 @@ pool_on_connect(const redisAsyncContext *ac) {
}
}
struct pool_reconnect {
struct event ev;
struct pool *p;
struct timeval tv;
};
static void
pool_can_connect(int fd, short event, void *ptr) {
struct pool_reconnect *pr = ptr;
struct pool *p = pr->p;
(void)fd;
(void)event;
free(pr);
pool_connect(p, 1);
}
static void
pool_schedule_reconnect(struct pool *p) {
struct pool_reconnect *pr = malloc(sizeof(struct pool_reconnect));
pr->p = p;
pr->tv.tv_sec = 0;
pr->tv.tv_usec = 100*1000; /* 0.1 sec*/
evtimer_set(&pr->ev, pool_can_connect, pr);
event_base_set(p->w->base, &pr->ev);
evtimer_add(&pr->ev, &pr->tv);
}
static void
pool_on_disconnect(const redisAsyncContext *ac, int status) {
@ -61,9 +96,8 @@ pool_on_disconnect(const redisAsyncContext *ac, int status) {
}
}
/* reconnect */
/* FIXME: schedule reconnect */
pool_connect(p, 1);
/* schedule reconnect */
pool_schedule_reconnect(p);
}
/**

Loading…
Cancel
Save