cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joseph Lynch (JIRA)" <>
Subject [jira] [Commented] (CASSANDRA-14358) OutboundTcpConnection can hang for many minutes when nodes restart
Date Mon, 09 Apr 2018 23:16:00 GMT


Joseph Lynch commented on CASSANDRA-14358:

Good news, Linux has support for a [socket option|]
since 2.6.37 called {{TCP_USER_TIMEOUT}} which implements [RFC5482|]
and does exactly what we want (ensures HA on a kept alive TCP connection). Netty also supports
[setting this option|] for epoll sockets as of
4.0.31, so we can set that on our internode TCP connections and get really high availability
networking without requiring OS tuning on Linux. The {{man tcp}} entry is educational:
       TCP_USER_TIMEOUT (since Linux 2.6.37)
              This  option takes an unsigned int as an argument.  When the value is greater
than 0, it specifies the maximum amount of time in milliseconds that trans‐
              mitted data may remain unacknowledged before TCP will forcibly close the corresponding
connection and return ETIMEDOUT to the application.  If the option
              value is specified as 0, TCP will to use the system default.

              Increasing  user  timeouts allows a TCP connection to survive extended periods
without end-to-end connectivity.  Decreasing user timeouts allows applica‐
              tions to "fail fast", if so desired.  Otherwise, failure may take up to 20 minutes
with the current system defaults in a normal WAN environment.

              This option can be set during any state of a TCP connection, but is effective
only during the synchronized states  of  a  connection  (ESTABLISHED,  FIN-
              WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, and LAST-ACK).  Moreover, when used
with the TCP keepalive (SO_KEEPALIVE) option, TCP_USER_TIMEOUT will override
              keepalive to determine when to close a connection due to keepalive failure.

              The option has no effect on when TCP retransmits a packet, nor when a keepalive
probe is sent.

              This option, like many others, will be inherited by the socket returned by accept(2),
if it was set on the listening socket.

              Further details on the user timeout feature can be found in RFC 793 and RFC
5482 ("TCP User Timeout Option").
I've started working on a [trunk patch|]
which will fix this on any Linux based deployment via the {{TCP_USER_TIMEOUT}} socket option. 

I've been testing with the reproduction steps I listed above using iptables and without my
patch Cassandra waits until the OS kills the connection in ~15-20 minutes, and with my patch
it kills it after ~10s.

> OutboundTcpConnection can hang for many minutes when nodes restart
> ------------------------------------------------------------------
>                 Key: CASSANDRA-14358
>                 URL:
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Streaming and Messaging
>         Environment: Cassandra 2.1.19 (also reproduced on 3.0.15), running with {{internode_encryption:
all}} and the EC2 multi region snitch on Linux 4.13 within the same AWS region. Smallest
cluster I've seen the problem on is 12 nodes, reproduces more reliably on 40+ and 300 node
clusters consistently reproduce on at least one node in the cluster.
> So all the connections are SSL and we're connecting on the internal ip addresses (not
the public endpoint ones).
> Potentially relevant sysctls:
> {noformat}
> /proc/sys/net/ipv4/tcp_syn_retries = 2
> /proc/sys/net/ipv4/tcp_synack_retries = 5
> /proc/sys/net/ipv4/tcp_keepalive_time = 7200
> /proc/sys/net/ipv4/tcp_keepalive_probes = 9
> /proc/sys/net/ipv4/tcp_keepalive_intvl = 75
> /proc/sys/net/ipv4/tcp_retries2 = 15
> {noformat}
>            Reporter: Joseph Lynch
>            Assignee: Joseph Lynch
>            Priority: Major
>         Attachments: 10 Minute Partition.pdf
> I've been trying to debug nodes not being able to see each other during longer (~5 minute+)
Cassandra restarts in 3.0.x and 2.1.x which can contribute to {{UnavailableExceptions}} during
rolling restarts of 3.0.x and 2.1.x clusters for us. I think I finally have a lead. It appears
that prior to trunk (with the awesome Netty refactor) we do not set socket connect timeouts
on SSL connections (in 2.1.x, 3.0.x, or 3.11.x) nor do we set {{SO_TIMEOUT}} as far as I can
tell on outbound connections either. I believe that this means that we could potentially block
forever on {{connect}} or {{recv}} syscalls, and we could block forever on the SSL Handshake
as well. I think that the OS will protect us somewhat (and that may be what's causing the
eventual timeout) but I think that given the right network conditions our {{OutboundTCPConnection}}
threads can just be stuck never making any progress until the OS intervenes.
> I have attached some logs of such a network partition during a rolling restart where
an old node in the cluster has a completely foobarred {{OutboundTcpConnection}} for ~10 minutes
before finally getting a {{ Connection timed out (Write failed)}}
and immediately successfully reconnecting. I conclude that the old node is the problem because
the new node (the one that restarted) is sending ECHOs to the old node, and the old node is
sending ECHOs and REQUEST_RESPONSES to the new node's ECHOs, but the new node is never getting
the ECHO's. This appears, to me, to indicate that the old node's {{OutboundTcpConnection}} thread
is just stuck and can't make any forward progress. By the time we could notice this and slap
TRACE logging on, the only thing we see is ~10 minutes later a {{SocketException}} inside
{{writeConnected}}'s flush and an immediate recovery. It is interesting to me that the exception
happens in {{writeConnected}} and it's a _connection timeout_ (and since we see {{Write failure}} I
believe that this can't be a connection reset), because my understanding is that we should
have a fully handshaked SSL connection at that point in the code.
> Current theory:
>  # "New" node restarts,  "Old" node calls [newSocket|]
>  # Old node starts [creating a new|] SSL
>  # SSLSocket calls [createSocket|],
which conveniently calls connect with a default timeout of "forever". We could hang here forever
until the OS kills us.
>  # If we continue, we get to [writeConnected|]
which eventually calls [flush|]
on the output stream and also can hang forever. I think the probability is especially high
when a node is restarting and is overwhelmed with SSL handshakes and such.
> I don't fully understand the attached traceback as it appears we are getting a {{Connection
Timeout}} from a {{send}} failure (my understanding is you can only get a connection timeout
prior to a send), but I think it's reasonable that we have a timeout configuration issue. I'd
like to try to make Cassandra robust to networking issues like this via maybe:
>  # Change the {{SSLSocket}} {{getSocket}} methods to provide connection timeouts of 2s
(equivalent to trunk's [timeout|])
>  # Appropriately set recv timeouts via {{SO_TIMEOUT}}, maybe something like 2 minutes
(in old versions via [setSoTimeout|],
in trunk via [SO_TIMEOUT|]
>  # Since we can't set send timeouts afaik (thanks java) maybe we can have some kind of
watchdog that ensures OutboundTcpConnection is making progress in its queue and if it doesn't
make any progress for ~30s-1m, forces a disconnect.
> If anyone has insight or suggestions, I'd be grateful. I am going to rule out if this
is keepalive duration by setting tcp_keepalive_probes to like 1 and maybe tcp_retries2 to
like 8 get more information about the state of the tcp connections the next time this happens.
It's a very rare bug and when it does happen I only have 10 minutes to jump on the nodes and
fix it before it fixes itself so I'll do my best.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message