Handle conn store in thread safe way (#1047)

* Handle conn store in thread safe way

* Change log line

* Fix proper error handling
This commit is contained in:
Zoltan Papp 2023-08-03 18:24:23 +02:00 committed by GitHub
parent 24e19ae287
commit d9686bae92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -12,7 +12,7 @@ func NewFactory(wgPort int) *Factory {
ebpfProxy := NewWGEBPFProxy(wgPort)
err := ebpfProxy.Listen()
if err != nil {
log.Errorf("failed to initialize ebpf proxy: %s", err)
log.Warnf("failed to initialize ebpf proxy, fallback to user space proxy: %s", err)
return f
}

View File

@ -69,7 +69,7 @@ func (p *WGEBPFProxy) Listen() error {
p.conn, err = net.ListenUDP("udp", &addr)
if err != nil {
cErr := p.Free()
if err != nil {
if cErr != nil {
log.Errorf("failed to close the wgproxy: %s", cErr)
}
return err
@ -153,7 +153,9 @@ func (p *WGEBPFProxy) proxyToRemote() {
return
}
p.turnConnMutex.Lock()
conn, ok := p.turnConnStore[uint16(addr.Port)]
p.turnConnMutex.Unlock()
if !ok {
log.Errorf("turn conn not found by port: %d", addr.Port)
continue