Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator {
"\tuser haproxy", "\tgroup haproxy", "\tstats socket /run/haproxy/admin.sock", "\tdaemon"};

private static String[] defaultsSection = {"defaults", "\tlog global", "\tmode tcp", "\toption dontlognull", "\tretries 3", "\toption redispatch",
"\toption forwardfor", "\toption httpclose", "\ttimeout connect 5000", "\ttimeout client 50000", "\ttimeout server 50000"};
"\toption forwardfor", "\toption httpclose", "\ttimeout connect 5000", "\ttimeout client 50000", "\ttimeout server 50000",
"", ""};

private static final long MAX_FIN_TIMEOUT = 50000;

private static String[] defaultListen = {"listen vmops", "\tbind 0.0.0.0:9", "\toption transparent"};

Expand Down Expand Up @@ -635,9 +638,11 @@ public String[] generateConfiguration(final LoadBalancerConfigCommand lbCmd) {
if (lbCmd.keepAliveEnabled) {
dSection.set(7, "\tno option httpclose");
}
long finTimeout = MAX_FIN_TIMEOUT;
if (lbCmd.idleTimeout > 0) {
dSection.set(9, "\ttimeout client " + Long.toString(lbCmd.idleTimeout));
dSection.set(10, "\ttimeout server " + Long.toString(lbCmd.idleTimeout));
finTimeout = Math.min(lbCmd.idleTimeout, MAX_FIN_TIMEOUT);
} else if (lbCmd.idleTimeout == 0) {
// .remove() is not allowed, only .set() operations are allowed as the list
// is a fixed size. So lets just mark the entry as blank.
Expand All @@ -648,6 +653,8 @@ public String[] generateConfiguration(final LoadBalancerConfigCommand lbCmd) {
// default HAProxy timeout values from defaultsSection for predictability.
logger.warn("Negative idleTimeout ({}) configured; retaining default HAProxy timeouts.", lbCmd.idleTimeout);
}
dSection.set(11, "\ttimeout client-fin " + Long.toString(finTimeout));
dSection.set(12, "\ttimeout server-fin " + Long.toString(finTimeout));
Comment on lines +656 to +657

if (logger.isDebugEnabled()) {
for (final String s : dSection) {
Expand Down
13 changes: 11 additions & 2 deletions core/src/test/java/com/cloud/network/HAProxyConfiguratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,22 @@ public void testGenerateConfigurationLoadBalancerIdleTimeoutConfigCommand() {

LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lba, "10.0.0.1", "10.1.0.1", "10.1.1.1", null, 1L, "4", true, 0L);
String result = genConfig(hpg, cmd);
assertTrue("idleTimeout of 0 should not generate 'timeout server' in the resulting haproxy config", !result.contains("\ttimeout server"));
assertTrue("idleTimeout of 0 should not generate 'timeout client' in the resulting haproxy config", !result.contains("\ttimeout client"));
assertTrue("idleTimeout of 0 should not generate 'timeout server' in the resulting haproxy config", !result.contains("\ttimeout server "));
assertTrue("idleTimeout of 0 should not generate 'timeout client' in the resulting haproxy config", !result.contains("\ttimeout client "));
assertTrue("idleTimeout of 0 leaves nothing else to bound half-closed connections, so they fall back to 50000",
result.contains("\ttimeout client-fin 50000") && result.contains("\ttimeout server-fin 50000"));

cmd = new LoadBalancerConfigCommand(lba, "10.0.0.1", "10.1.0.1", "10.1.1.1", null, 1L, "4", true, 1234L);
result = genConfig(hpg, cmd);
assertTrue("idleTimeout of 1234 should result in 'timeout server 1234' in the resulting haproxy config", result.contains("\ttimeout server 1234"));
assertTrue("idleTimeout of 1234 should result in 'timeout client 1234' in the resulting haproxy config", result.contains("\ttimeout client 1234"));
assertTrue("a half-closed connection must not outlive an active one, so the fin timeout tracks a smaller idleTimeout",
result.contains("\ttimeout client-fin 1234") && result.contains("\ttimeout server-fin 1234"));

cmd = new LoadBalancerConfigCommand(lba, "10.0.0.1", "10.1.0.1", "10.1.1.1", null, 1L, "4", true, 3600000L);
result = genConfig(hpg, cmd);
assertTrue("idleTimeout of 3600000 should still be capped to 50000 for half-closed connections",
result.contains("\ttimeout client-fin 50000") && result.contains("\ttimeout server-fin 50000"));
}

/**
Expand Down