From 7d878bd22318d6a8a5abca40ce732d538e133826 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 4 Oct 2014 03:13:04 +1000 Subject: [PATCH] Force close when dropping a client with a reset using SO_LINGER and give a warning on close failure --- src/connector.c | 4 ++++ src/libckpool.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/connector.c b/src/connector.c index 69ec4825..71941848 100644 --- a/src/connector.c +++ b/src/connector.c @@ -155,6 +155,10 @@ static int drop_client(conn_instance_t *ci, client_instance_t *client) ck_wlock(&ci->lock); fd = client->fd; if (fd != -1) { + const struct linger so_linger = { 1, 0 }; + + if (unlikely(setsockopt(client->fd, SOL_SOCKET, SO_LINGER, &so_linger, sizeof(so_linger)))) + LOGWARNING("setsockopt failed with errno %d:%s", errno, strerror(errno)); Close(client->fd); HASH_DEL(clients, client); HASH_DELETE(fdhh, fdclients, client); diff --git a/src/libckpool.c b/src/libckpool.c index 49232894..731132ae 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -437,7 +437,8 @@ void _Close(int *fd) if (*fd < 0) return; LOGDEBUG("Closing file handle %d", *fd); - close(*fd); + if (unlikely(close(*fd))) + LOGWARNING("Close of fd %d failed with errno %d:%s", *fd, errno, strerror(errno)); *fd = -1; }