Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Nov 9, 2020
1 parent 6312784 commit 0bf667d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/listener/virtual_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package listener
import (
"context"
"fmt"
"io"
"net"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -31,19 +32,25 @@ func (v *virtualListenerManager) Listen(ctx context.Context, network, address st

listener := newVirtualListener(v, addr)

var old io.Closer
defer func() {
if old != nil {
old.Close()
}
}()
v.mut.Lock()
defer v.mut.Unlock()
if addr.IP.Equal(ipv4zero) {
l, ok := v.port[addr.Port]
if ok {
l.Close()
old = l
}
v.port[addr.Port] = listener
} else {
a := addr.String()
l, ok := v.address[a]
if ok {
l.Close()
old = l
}
v.address[a] = listener
}
Expand Down

0 comments on commit 0bf667d

Please sign in to comment.