Skip to content

Commit 120d206

Browse files
committed
fix: close TLS connection on STOMP connect failure
When stomp.Connect() fails after a successful tls.Dial(), the underlying net.Conn was leaked. This fix ensures the TLS connection is properly closed when the STOMP protocol handshake fails, preventing file descriptor leaks in both publisher and consumer.
1 parent d5a29cd commit 120d206

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

pkg/stomp/consumer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func (c *StompConsumer) Connect() {
8282
err = tlsErr
8383
} else {
8484
conn, err = stomp.Connect(netConn, o...)
85+
if err != nil {
86+
_ = netConn.Close()
87+
}
8588
}
8689
} else {
8790
conn, err = stomp.Dial("tcp", parsedUri.Broker, o...)

pkg/stomp/publisher.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func (p *StompPublisher) Connect() {
7575
err = tlsErr
7676
} else {
7777
conn, err = stomp.Connect(netConn, o...)
78+
if err != nil {
79+
_ = netConn.Close()
80+
}
7881
}
7982
} else {
8083
conn, err = stomp.Dial("tcp", parsedUri.Broker, o...)

0 commit comments

Comments
 (0)