Close proxy reading in case of eof

This commit is contained in:
Zoltán Papp 2024-06-21 00:55:30 +02:00
parent 06ceac65de
commit bfe60c01ba

View File

@ -3,6 +3,7 @@ package wgproxy
import ( import (
"context" "context"
"fmt" "fmt"
"io"
"net" "net"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -64,7 +65,6 @@ func (p *WGUserSpaceProxy) Free() error {
// proxyToRemote proxies everything from Wireguard to the RemoteKey peer // proxyToRemote proxies everything from Wireguard to the RemoteKey peer
// blocks // blocks
func (p *WGUserSpaceProxy) proxyToRemote() { func (p *WGUserSpaceProxy) proxyToRemote() {
buf := make([]byte, 1500) buf := make([]byte, 1500)
for { for {
select { select {
@ -78,6 +78,9 @@ func (p *WGUserSpaceProxy) proxyToRemote() {
_, err = p.remoteConn.Write(buf[:n]) _, err = p.remoteConn.Write(buf[:n])
if err != nil { if err != nil {
if err == io.EOF {
p.cancel()
}
continue continue
} }
} }
@ -96,6 +99,10 @@ func (p *WGUserSpaceProxy) proxyToLocal() {
default: default:
n, err := p.remoteConn.Read(buf) n, err := p.remoteConn.Read(buf)
if err != nil { if err != nil {
if err == io.EOF {
p.cancel()
return
}
continue continue
} }