-
Notifications
You must be signed in to change notification settings - Fork 24
/
14342-global-connection-cache.patch
79 lines (68 loc) · 2.71 KB
/
14342-global-connection-cache.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From 12b51e3ef25585789e4299dd2ceadacbccbeeda2 Mon Sep 17 00:00:00 2001
From: Alexis Mousset <alexis.mousset@rudder.io>
Date: Tue, 19 Feb 2019 17:57:31 +0100
Subject: [PATCH] CFE-2678: Global connection cache
Currently the connection cache is reset after each bundle pass.
This limits its effectivity, as all policies do not group file copies
in the same bundle pass. This was apprently done to limit the risk
of reusing broken connections.
This commit keeps a unique connection cache for the whole agent run,
and adds an error detection mechanism to avoid reusing broken cached
connections.
---
cf-agent/cf-agent.c | 5 +++--
libcfnet/conn_cache.c | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/cf-agent/cf-agent.c b/cf-agent/cf-agent.c
index c78e879d4d..9a0b3f8577 100644
--- a/cf-agent/cf-agent.c
+++ b/cf-agent/cf-agent.c
@@ -267,10 +267,13 @@ int main(int argc, char *argv[])
GenericAgentPostLoadInit(ctx);
ThisAgentInit();
+ ConnCache_Init();
BeginAudit();
KeepPromises(ctx, policy, config);
+ ConnCache_Destroy();
+
if (EvalAborted(ctx))
{
ret = EC_EVAL_ABORTED;
@@ -1812,7 +1815,6 @@ static int NewTypeContext(TypeSequence type)
break;
case TYPE_SEQUENCE_FILES:
- ConnCache_Init();
break;
case TYPE_SEQUENCE_PROCESSES:
@@ -1846,7 +1848,6 @@ static void DeleteTypeContext(EvalContext *ctx, TypeSequence type)
break;
case TYPE_SEQUENCE_FILES:
- ConnCache_Destroy();
break;
case TYPE_SEQUENCE_PROCESSES:
diff --git a/libcfnet/conn_cache.c b/libcfnet/conn_cache.c
index 1c9e7d65d9..67aef3b84a 100644
--- a/libcfnet/conn_cache.c
+++ b/libcfnet/conn_cache.c
@@ -128,6 +128,22 @@ AgentConnection *ConnCache_FindIdleMarkBusy(const char *server,
{
assert(svp->status == CONNCACHE_STATUS_IDLE);
+ // Check connection state before returning it
+ int error = 0;
+ socklen_t len = sizeof(error);
+ if (getsockopt(svp->conn->conn_info->sd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
+ {
+ Log(LOG_LEVEL_DEBUG, "FindIdle: found connection to '%s' but could not get socket status, skipping.",
+ server);
+ continue;
+ }
+ if (error != 0)
+ {
+ Log(LOG_LEVEL_DEBUG, "FindIdle: found connection to '%s' but connection is broken, skipping.",
+ server);
+ continue;
+ }
+
Log(LOG_LEVEL_VERBOSE, "FindIdle:"
" found connection to '%s' already open and ready.",
server);