Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e2de15

Browse files
committed
Fix redis_session
Prevent infinite loop when redis_sock_server_open failed. Check pool->lock_status.session_key is not NULL in PS_CLOSE_FUNC.
1 parent 6f7ddd2 commit 4e2de15

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

redis_session.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,16 @@ redis_pool_get_sock(redis_pool *pool, const char *key TSRMLS_DC) {
209209
if (rpm->auth && rpm->redis_sock->status != REDIS_SOCK_STATUS_CONNECTED) {
210210
needs_auth = 1;
211211
}
212-
if (redis_sock_server_open(rpm->redis_sock TSRMLS_CC) < 0) {
213-
continue;
214-
}
215-
if (needs_auth) {
216-
redis_pool_member_auth(rpm TSRMLS_CC);
217-
}
218-
if (rpm->database >= 0) { /* default is -1 which leaves the choice to redis. */
219-
redis_pool_member_select(rpm TSRMLS_CC);
220-
}
212+
if (redis_sock_server_open(rpm->redis_sock TSRMLS_CC) == 0) {
213+
if (needs_auth) {
214+
redis_pool_member_auth(rpm TSRMLS_CC);
215+
}
216+
if (rpm->database >= 0) { /* default is -1 which leaves the choice to redis. */
217+
redis_pool_member_select(rpm TSRMLS_CC);
218+
}
221219

222-
return rpm;
220+
return rpm;
221+
}
223222
}
224223
i += rpm->weight;
225224
rpm = rpm->next;
@@ -546,11 +545,13 @@ PS_CLOSE_FUNC(redis)
546545
redis_pool *pool = PS_GET_MOD_DATA();
547546

548547
if (pool) {
549-
redis_pool_member *rpm = redis_pool_get_sock(pool, ZSTR_VAL(pool->lock_status.session_key) TSRMLS_CC);
548+
if (pool->lock_status.session_key) {
549+
redis_pool_member *rpm = redis_pool_get_sock(pool, ZSTR_VAL(pool->lock_status.session_key) TSRMLS_CC);
550550

551-
RedisSock *redis_sock = rpm ? rpm->redis_sock : NULL;
552-
if (redis_sock) {
553-
lock_release(redis_sock, &pool->lock_status TSRMLS_CC);
551+
RedisSock *redis_sock = rpm ? rpm->redis_sock : NULL;
552+
if (redis_sock) {
553+
lock_release(redis_sock, &pool->lock_status TSRMLS_CC);
554+
}
554555
}
555556

556557
redis_pool_free(pool TSRMLS_CC);

0 commit comments

Comments
 (0)