Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit a778c5f

Browse files
authored
Ensure rtc conn is closed on error (#438)
1 parent 4c89550 commit a778c5f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

wsnet/dial.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/pion/datachannel"
1515
"github.com/pion/webrtc/v3"
1616
"golang.org/x/net/proxy"
17+
"golang.org/x/xerrors"
1718
"nhooyr.io/websocket"
1819

1920
"cdr.dev/slog"
@@ -112,6 +113,11 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
112113
iceServers: rtc.GetConfiguration().ICEServers,
113114
rtc: rtc.ConnectionState(),
114115
}
116+
117+
closeErr := rtc.Close()
118+
if closeErr != nil {
119+
log.Warn(context.Background(), "close rtc connection on dial failure", slog.Error(closeErr))
120+
}
115121
}
116122
}()
117123

@@ -170,9 +176,12 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
170176
connClosers: []io.Closer{ctrl},
171177
}
172178

173-
// This is on a separate line so the defer above catches it.
174179
err = dialer.negotiate(ctx)
175-
return dialer, err
180+
if err != nil {
181+
return nil, xerrors.Errorf("negotiate rtc connection: %w", err)
182+
}
183+
184+
return dialer, nil
176185
}
177186

178187
// Dialer enables arbitrary dialing to any network and address

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy