fix: potential race conditions with non-local err

Some of the changes do not appear to have a potential race condition,
so there it is purely a refactor,
while in others (e.g. in broker.go and in proxy/lib/snowflake.go)
we do use the same variable from multiple threads / functions.
This commit is contained in:
WofWca 2025-03-02 15:24:39 +04:00
parent 01819eee32
commit 1923803124
5 changed files with 13 additions and 14 deletions

View file

@ -241,7 +241,7 @@ func (c *WebRTCPeer) connect(
}
case <-time.After(DataChannelTimeout):
c.transport.Close()
err = errors.New("timeout waiting for DataChannel.OnOpen")
err := errors.New("timeout waiting for DataChannel.OnOpen")
if natPolicy != nil {
natPolicy.Failure(actualNatType, natTypeToSend)
}
@ -259,7 +259,6 @@ func (c *WebRTCPeer) preparePeerConnection(
config *webrtc.Configuration,
keepLocalAddresses bool,
) error {
var err error
s := webrtc.SettingEngine{}
if !keepLocalAddresses {
@ -282,7 +281,7 @@ func (c *WebRTCPeer) preparePeerConnection(
vnet, _ = stdnet.NewNet()
if c.proxy != nil {
if err = proxy.CheckProxyProtocolSupport(c.proxy); err != nil {
if err := proxy.CheckProxyProtocolSupport(c.proxy); err != nil {
return err
}
socksClient := proxy.NewSocks5UDPClient(c.proxy)
@ -291,6 +290,7 @@ func (c *WebRTCPeer) preparePeerConnection(
s.SetNet(vnet)
api := webrtc.NewAPI(webrtc.WithSettingEngine(s))
var err error
c.pc, err = api.NewPeerConnection(*config)
if err != nil {
log.Printf("NewPeerConnection ERROR: %s", err)