Skip to content

Commit 869f3d0

Browse files
authoredAug 19, 2023
Make redisEnableKeepAlive a no-op on AF_UNIX connections. (#1215)
Fixes #1185
1 parent 039385b commit 869f3d0

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/*.pc
88
*.dSYM
99
tags
10+
compile_commands.json

‎net.c

+4
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ int redisKeepAlive(redisContext *c, int interval) {
173173
int val = 1;
174174
redisFD fd = c->fd;
175175

176+
/* TCP_KEEPALIVE makes no sense with AF_UNIX connections */
177+
if (c->connection_type == REDIS_CONN_UNIX)
178+
return REDIS_ERR;
179+
176180
#ifndef _WIN32
177181
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
178182
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));

‎test.c

+19
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,24 @@ static void test_tcp_options(struct config cfg) {
431431
redisFree(c);
432432
}
433433

434+
static void test_unix_keepalive(struct config cfg) {
435+
redisContext *c;
436+
redisReply *r;
437+
438+
c = do_connect(cfg);
439+
440+
test("Setting TCP_KEEPALIVE on a unix socket returns an error: ");
441+
test_cond(redisEnableKeepAlive(c) == REDIS_ERR && c->err == 0);
442+
443+
test("Setting TCP_KEEPALIVE on a unix socket doesn't break the connection: ");
444+
r = redisCommand(c, "PING");
445+
test_cond(r != NULL && r->type == REDIS_REPLY_STATUS && r->len == 4 &&
446+
!memcmp(r->str, "PONG", 4));
447+
freeReplyObject(r);
448+
449+
redisFree(c);
450+
}
451+
434452
static void test_reply_reader(void) {
435453
redisReader *reader;
436454
void *reply, *root;
@@ -2363,6 +2381,7 @@ int main(int argc, char **argv) {
23632381
test_blocking_connection_timeouts(cfg);
23642382
test_blocking_io_errors(cfg);
23652383
test_invalid_timeout_errors(cfg);
2384+
test_unix_keepalive(cfg);
23662385
if (throughput) test_throughput(cfg);
23672386
} else {
23682387
test_skipped();

0 commit comments

Comments
 (0)
Please sign in to comment.