Skip to content

Commit efc88b2

Browse files
committed
Don't leak open connections when the TLS handshake fails
1 parent 1325ff8 commit efc88b2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

driver/src/main/java/org/neo4j/driver/internal/net/ChannelFactory.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,22 @@ static ByteChannel create( BoltServerAddress address, SecurityPlan securityPlan,
4444

4545
if ( securityPlan.requiresEncryption() )
4646
{
47-
channel = TLSSocketChannel.create( address, securityPlan, soChannel, log );
47+
try
48+
{
49+
channel = TLSSocketChannel.create( address, securityPlan, soChannel, log );
50+
}
51+
catch ( Exception e )
52+
{
53+
try
54+
{
55+
channel.close();
56+
}
57+
catch( IOException e2 )
58+
{
59+
// best effort
60+
}
61+
throw e;
62+
}
4863
}
4964

5065
if ( log.isTraceEnabled() )

0 commit comments

Comments
 (0)