mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:14:03 +03:00
Guarantee of closing sockets after context is done
This commit is contained in:
@@ -47,6 +47,7 @@ func (p *Proxy) accept(conn net.Conn) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
defer func() {
|
||||
cancel()
|
||||
conn.Close() // nolint: errcheck
|
||||
|
||||
if err := recover(); err != nil {
|
||||
@@ -74,6 +75,12 @@ func (p *Proxy) accept(conn net.Conn) {
|
||||
}
|
||||
defer serverConn.(io.Closer).Close() // nolint: errcheck
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
serverConn.(io.Closer).Close()
|
||||
clientConn.(io.Closer).Close()
|
||||
}()
|
||||
|
||||
wait := &sync.WaitGroup{}
|
||||
wait.Add(2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user