Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1663609

Summary: CLOSE_WAIT leak in qpid-cpp-client when trying to reconnect over unreliable network
Product: Red Hat Enterprise MRG Reporter: Pavel Moravec <pmoravec>
Component: qpid-cppAssignee: messaging-bugs <messaging-bugs>
Status: CLOSED ERRATA QA Contact: Zdenek Kraus <zkraus>
Severity: high Docs Contact:
Priority: high    
Version: 3.2CC: jfrancin, jross, mcressma, pmoravec, sjay, zkraus
Target Milestone: 3.2.12   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qpid-cpp-1.36.0-21 Doc Type: Bug Fix
Doc Text:
Cause: When a C++ client is trying to reconnect over an unreliable network that drops a lot of packets, the client library sometimes fails to close the TCP connection on its end. The connection can get stuck in CLOSE_WAIT status and the associated resources are held indefinitely. Consequence: A series of these leaks can cause resources issues, such as FDs running out and preventing new client connections to the broker. Fix: In cases where the connection is aborted due to things like a faulty network, we now explicitly close the socket to avoid the leak. Result: This allows the client to reconnect without leaking any associated resources.
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-02-21 13:35:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
reproducer client
none
proposed patch none

Description Pavel Moravec 2019-01-05 12:03:10 UTC
Description of problem:
When a C++ client is trying to reconnect over unreliable network that drops a lot of packets, the client library sometimes forgets to close TCP connection on its end. New one is established later on, server properly closed the semi-hung, this one remains in CLOSE_WAIT status forever - a CLOSE_WAIT leak.

Next CLOSE_WAIT leaks can subsequently happen, causing ulimit in FDs hit after some time and preventing the client to open a new connection to the broker.

A simple patch proposed by the customer++ , I acknowledge its logic though some developer more familiar with that code should do proper review.


Version-Release number of selected component (if applicable):
qpid-cpp-client 1.36.0-20 or older


How reproducible:
100% over some time


Steps to Reproduce:
1. Update in attached client program IP address to yours qpid broker one

2. Compile attached client program:
g++ client.cpp -lqpidmessaging -I/usr/include -o leak_repro -std=gnu++0x

3. Run it:
./leak_repro

4. Add iptables rule to drop 4/5 of packets towards qpidd:
iptables -A OUTPUT -p tcp --destination-port 5672 -m statistic --mode random --probability 0.80 -j DROP

5. monitor CLOSE_WAITs on outgoing connections


Actual results:
5. after few minutes, netstat shows a growing list of CLOSE_WAITs on client side only


Expected results:
5. no CLOSE_WAIT (other than very short-living)


Additional info:

Comment 1 Pavel Moravec 2019-01-05 12:06:34 UTC
Created attachment 1518639 [details]
reproducer client

just update IP address to your broker one

Comment 2 Pavel Moravec 2019-01-05 12:10:56 UTC
Created attachment 1518640 [details]
proposed patch

Proposed patch (pre-verified against the reproducer on my system).

Rationale: 
- per tcpdumps, CLOSE_WAITs happen when TCP connection is established and AMQP connection is opening via this scenario:
  - "AMQP" frame sent from client
  - "AMQP" and connection.start replied from broker
  - then silence due to all packets dropped
  - then broker sends FIN+ACK
- This line of code is executed: https://github.com/apache/qpid-cpp/blob/master/src/qpid/client/TCPConnector.cpp#L164
- but it does not close the socket
- patch executes the same methods + calls socket->close();

Comment 4 Pavel Moravec 2019-01-06 21:53:42 UTC
The bug affects upstream the same way. And the patch fixes the scenario from the bug in upstream as well.

Comment 7 Zdenek Kraus 2019-02-08 13:16:26 UTC
This issue was tested with RHEL 6 and 7, with following packages:

qpid-cpp-server-1.36.0-21

Fix works as expected.
->VERIFIED

Comment 9 errata-xmlrpc 2019-02-21 13:35:28 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2019:0390