From 551b29470a175bd01c42a436cd807331b3021d40 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Sat, 22 Jun 2024 17:31:16 +0200 Subject: [PATCH] conn.go: Return unacknowledged packets to packet pool on close. --- conn.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/conn.go b/conn.go index a7b04c3..c45592c 100644 --- a/conn.go +++ b/conn.go @@ -309,6 +309,15 @@ func (conn *Conn) closeImmediately() { _, _ = conn.Write([]byte{message.IDDisconnectNotification}) conn.handler.close(conn) close(conn.closed) + + conn.mu.Lock() + defer conn.mu.Unlock() + // Make sure to return all unacknowledged packets to the packet pool. + for _, record := range conn.retransmission.unacknowledged { + record.pk.content = record.pk.content[:0] + packetPool.Put(record.pk) + } + clear(conn.retransmission.unacknowledged) }) }