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

Commit 177839f

Browse files
committed
Ensure rtc conn is closed on error (#438)
(cherry picked from commit a778c5f) (cherry picked from commit 677577f)
1 parent 2954cab commit 177839f

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"
@@ -111,6 +112,11 @@ func Dial(ctx context.Context, conn net.Conn, options *DialOptions) (*Dialer, er
111112
iceServers: rtc.GetConfiguration().ICEServers,
112113
rtc: rtc.ConnectionState(),
113114
}
115+
116+
closeErr := rtc.Close()
117+
if closeErr != nil {
118+
log.Warn(context.Background(), "close rtc connection on dial failure", slog.Error(closeErr))
119+
}
114120
}
115121
}()
116122

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

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

177186
// 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