Skip to content

Commit 8e46f44

Browse files
authored
Optimize stopping CaptivePortalHandler (#2151)
* Optimize stopping CaptivePortalHandler * Still use unbuffered channel as we close it instead of sending a signal
1 parent 3d641b7 commit 8e46f44

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

dnscrypt-proxy/coldstart.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ type CaptivePortalHandler struct {
2020

2121
func (captivePortalHandler *CaptivePortalHandler) Stop() {
2222
for _, cancelChannel := range captivePortalHandler.cancelChannels {
23-
cancelChannel <- struct{}{}
24-
<-cancelChannel
23+
close(cancelChannel)
2524
}
2625
}
2726

@@ -84,7 +83,6 @@ func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, i
8483
exit := false
8584
select {
8685
case <-cancelChannel:
87-
cancelChannel <- struct{}{}
8886
exit = true
8987
default:
9088
}
@@ -96,12 +94,6 @@ func handleColdStartClient(clientPc *net.UDPConn, cancelChannel chan struct{}, i
9694
}
9795
if err != nil {
9896
dlog.Warn(err)
99-
select {
100-
case <-cancelChannel:
101-
cancelChannel <- struct{}{}
102-
default:
103-
cancelChannel = make(chan struct{}, 1)
104-
}
10597
return true
10698
}
10799
packet := buffer[:length]

0 commit comments

Comments
 (0)