Skip to content

Commit

Permalink
transport: fixed lazyDnsConn earlyReserveCallWg dead lock
Browse files Browse the repository at this point in the history
  • Loading branch information
IrineSistiana committed Nov 6, 2023
1 parent b16a871 commit a281fdb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/upstream/transport/conn_lazy_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@ type lazyDnsConnEarlyReservedExchanger lazyDnsConn
var _ ReservedExchanger = (*lazyDnsConnEarlyReservedExchanger)(nil)

func (ote *lazyDnsConnEarlyReservedExchanger) ExchangeReserved(ctx context.Context, q []byte) (resp *[]byte, err error) {
defer ote.WithdrawReserved()
defer func() {
ote.mu.Lock()
ote.reservedQuery--
ote.mu.Unlock()
}()

select {
case <-ctx.Done():
ote.earlyReserveCallWg.Done()
return nil, context.Cause(ctx)
case <-ote.dialFinished:
dc, err := ote.c, ote.dialErr
Expand All @@ -153,7 +158,8 @@ func (ote *lazyDnsConnEarlyReservedExchanger) ExchangeReserved(ctx context.Conte
}

func (ote *lazyDnsConnEarlyReservedExchanger) WithdrawReserved() {
ote.earlyReserveCallWg.Done()
ote.mu.Lock()
defer ote.mu.Unlock()
ote.reservedQuery--
ote.mu.Unlock()
}

0 comments on commit a281fdb

Please sign in to comment.