From 5be576e0fe6e1d5b01612565731cd08a48e02c1b Mon Sep 17 00:00:00 2001
From: Ben Chess <bchess@openai.com>
Date: Fri, 3 Feb 2023 22:40:01 +0000
Subject: [PATCH] output: set tcp keepalive flag when desired

Update the stream keepalive flag to match the net keepalive setting.
This is required for the upstream connection to get recycled

Signed-off-by: Ben Chess <bchess@openai.com>
---
 src/flb_output.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/flb_output.c b/src/flb_output.c
index 64756c090e4..ee50ed80a2a 100644
--- a/src/flb_output.c
+++ b/src/flb_output.c
@@ -1365,6 +1365,10 @@ int flb_output_upstream_set(struct flb_upstream *u, struct flb_output_instance *
         flags |= FLB_IO_TCP_KA;
     }
 
+    if (ins->net_setup.keepalive == FLB_TRUE) {
+        flags |= FLB_IO_TCP_KA;
+    }
+
     /* Set flags */
     flb_stream_enable_flags(&u->base, flags);