Skip to content

Commit 4926dd9

Browse files
authored
Porting the memory leak fix from dev and changing version to 1.2.13 (#355)
* Fixing a minor memory leak. (#353) # Conflicts: # azure-servicebus/src/main/java/com/microsoft/azure/servicebus/amqp/ConnectionHandler.java # pom.xml * Cahnging version to 1.2.13
1 parent 2c04546 commit 4926dd9

File tree

5 files changed

+61
-12
lines changed

5 files changed

+61
-12
lines changed

azure-servicebus/src/main/java/com/microsoft/azure/servicebus/amqp/BaseLinkHandler.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public BaseLinkHandler(final IAmqpLink amqpLink) {
2121
@Override
2222
public void onLinkLocalClose(Event event) {
2323
Link link = event.getLink();
24-
if (link != null) {
24+
if (link != null) {
2525
TRACE_LOGGER.debug("local link close. linkName:{}", link.getName());
26+
27+
checkAndFreeLink(link);
28+
closeSession(link);
2629
}
27-
28-
closeSession(link);
2930
}
3031

3132
@Override
@@ -40,8 +41,9 @@ public void onLinkRemoteClose(Event event) {
4041

4142
ErrorCondition condition = link.getRemoteCondition();
4243
this.processOnClose(link, condition);
44+
checkAndFreeLink(link);
4345
closeSession(link);
44-
}
46+
}
4547
}
4648

4749
@Override
@@ -57,7 +59,16 @@ public void onLinkRemoteDetach(Event event) {
5759
this.processOnClose(link, link.getRemoteCondition());
5860
closeSession(link);
5961
}
60-
62+
}
63+
64+
@Override
65+
public void onLinkFinal(Event event)
66+
{
67+
Link link = event.getLink();
68+
if(link != null)
69+
{
70+
link.attachments().clear();
71+
}
6172
}
6273

6374
public void processOnClose(Link link, ErrorCondition condition) {
@@ -72,8 +83,15 @@ public void processOnClose(Link link, Exception exception) {
7283
this.underlyingEntity.onError(exception);
7384
}
7485

75-
private void closeSession(Link link) {
86+
private static void closeSession(Link link) {
7687
if (link.getSession() != null && link.getSession().getLocalState() != EndpointState.CLOSED)
7788
link.getSession().close();
7889
}
90+
91+
private static void checkAndFreeLink(Link link) {
92+
if (link.getLocalState() == EndpointState.CLOSED && link.getRemoteState() == EndpointState.CLOSED)
93+
{
94+
link.free();
95+
}
96+
}
7997
}

azure-servicebus/src/main/java/com/microsoft/azure/servicebus/amqp/ConnectionHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import java.security.NoSuchAlgorithmException;
88
import java.util.HashMap;
99
import java.util.Map;
10-
1110
import javax.net.ssl.SSLContext;
12-
1311
import org.apache.qpid.proton.Proton;
1412
import org.apache.qpid.proton.amqp.Symbol;
1513
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
@@ -179,6 +177,11 @@ public void onConnectionRemoteClose(Event event)
179177
@Override
180178
public void onConnectionFinal(Event event) {
181179
TRACE_LOGGER.debug("onConnectionFinal: hostname:{}", event.getConnection().getHostname());
180+
Connection connection = event.getConnection();
181+
if(connection != null)
182+
{
183+
connection.attachments().clear();
184+
}
182185
}
183186

184187
@Override

azure-servicebus/src/main/java/com/microsoft/azure/servicebus/amqp/ReactorHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ public void onReactorInit(Event e)
2121
{
2222
TRACE_LOGGER.debug("reactor.onReactorInit");
2323

24-
final Reactor reactor = e.getReactor();
24+
Reactor reactor = e.getReactor();
2525
reactor.setTimeout(ClientConstants.REACTOR_IO_POLL_TIMEOUT);
2626
}
2727

2828
@Override
2929
public void onReactorFinal(Event e)
3030
{
3131
TRACE_LOGGER.debug("reactor.onReactorFinal");
32+
Reactor reactor = e.getReactor();
33+
if(reactor != null)
34+
{
35+
reactor.attachments().clear();
36+
}
3237
}
3338
}

azure-servicebus/src/main/java/com/microsoft/azure/servicebus/amqp/SessionHandler.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public void onSessionRemoteOpen(Event e)
3939
public void onSessionLocalClose(Event e)
4040
{
4141
TRACE_LOGGER.debug("onSessionLocalClose - entityName: {}, condition: {}", this.name, e.getSession().getCondition() == null ? "none" : e.getSession().getCondition().toString());
42+
Session session = e.getSession();
43+
if (session != null)
44+
{
45+
checkAndFreeSession(session);
46+
}
4247
}
4348

4449
@Override
@@ -47,15 +52,33 @@ public void onSessionRemoteClose(Event e)
4752
TRACE_LOGGER.debug("onSessionRemoteClose - entityName: {}, condition: {}", this.name, e.getSession().getCondition() == null ? "none" : e.getSession().getCondition().toString());
4853

4954
Session session = e.getSession();
50-
if (session != null && session.getLocalState() != EndpointState.CLOSED)
55+
if (session != null)
5156
{
52-
session.close();
57+
if(session.getLocalState() != EndpointState.CLOSED)
58+
{
59+
session.close();
60+
}
61+
62+
checkAndFreeSession(session);
5363
}
5464
}
5565

5666
@Override
5767
public void onSessionFinal(Event e)
5868
{
5969
TRACE_LOGGER.debug("onSessionFinal - entityName: {}", this.name);
70+
Session session = e.getSession();
71+
if(session != null)
72+
{
73+
session.attachments().clear();
74+
}
75+
}
76+
77+
private static void checkAndFreeSession(Session session)
78+
{
79+
if(session.getLocalState() == EndpointState.CLOSED && session.getRemoteState() == EndpointState.CLOSED)
80+
{
81+
session.free();
82+
}
6083
}
6184
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<proton-j-version>0.31.0</proton-j-version>
1414
<junit-version>4.12</junit-version>
1515
<slf4j-version>1.7.0</slf4j-version>
16-
<client-current-version>1.2.12</client-current-version>
16+
<client-current-version>1.2.13</client-current-version>
1717
</properties>
1818

1919
<modules>

0 commit comments

Comments
 (0)