Skip to content

Commit

Permalink
release reserved memory on close
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Feb 28, 2022
1 parent abd728e commit 239b975
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion multiplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ type Multiplex struct {
channels map[streamID]*Stream
chLock sync.Mutex

bufIn, bufOut chan struct{}
bufIn, bufOut chan struct{}
reservedMemory int
}

// NewMultiplex creates a new multiplexer session.
Expand Down Expand Up @@ -128,6 +129,7 @@ func NewMultiplex(con net.Conn, initiator bool, memoryManager MemoryManager) (*M
if err = mp.memoryManager.ReserveMemory(2*MaxMessageSize, prio); err != nil {
break
}
mp.reservedMemory += 2 * MaxMessageSize
bufs++
}

Expand Down Expand Up @@ -186,6 +188,7 @@ func (mp *Multiplex) closeNoWait() {
select {
case <-mp.shutdown:
default:
mp.memoryManager.ReleaseMemory(mp.reservedMemory)
mp.con.Close()
close(mp.shutdown)
}
Expand Down

0 comments on commit 239b975

Please sign in to comment.