Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb020a5

Browse files
fix: Update pion/webrtc to fix ICE negotiation race (#153)
* Add trace logging for pion (dtls,ice,pc) * Temporarily disable postgres tests to spend more cycles on mock tests * experiment: Add trace logging for WebRTC offer and answer * Use forked pion/webrtc Co-authored-by: Bryan Phelps <[email protected]>
1 parent e75bde4 commit fb020a5

File tree

4 files changed

+37
-40
lines changed

4 files changed

+37
-40
lines changed

.github/workflows/coder.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ jobs:
7979
- uses: actions/setup-go@v2
8080
with:
8181
go-version: "^1.17"
82-
- run:
83-
curl -sSL
82+
- run: curl -sSL
8483
https://github.com/kyleconroy/sqlc/releases/download/v1.11.0/sqlc_1.11.0_linux_amd64.tar.gz
8584
| sudo tar -C /usr/bin -xz sqlc
8685

@@ -156,15 +155,13 @@ jobs:
156155
terraform_wrapper: false
157156

158157
- name: Test with Mock Database
159-
run:
160-
gotestsum --jsonfile="gotests.json" --packages="./..." --
158+
run: gotestsum --jsonfile="gotests.json" --packages="./..." --
161159
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
162-
-count=3 -race -short -parallel=2
160+
-count=5 -race -short -parallel=2
163161

164162
- name: Test with PostgreSQL Database
165163
if: runner.os == 'Linux'
166-
run:
167-
DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
164+
run: DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
168165
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
169166
-count=1 -race -parallel=2
170167

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/pion/datachannel v1.5.2
2828
github.com/pion/logging v0.2.2
2929
github.com/pion/transport v0.13.0
30-
github.com/pion/webrtc/v3 v3.1.19
30+
github.com/pion/webrtc/v3 v3.1.21
3131
github.com/spf13/cobra v1.3.0
3232
github.com/stretchr/testify v1.7.0
3333
github.com/unrolled/secure v1.0.9
@@ -106,7 +106,7 @@ require (
106106
github.com/zclconf/go-cty v1.10.0 // indirect
107107
github.com/zeebo/errs v1.2.2 // indirect
108108
go.opencensus.io v0.23.0 // indirect
109-
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba // indirect
109+
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
110110
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
111111
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
112112
golang.org/x/text v0.3.7 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,8 @@ github.com/pion/turn/v2 v2.0.6 h1:AsXjSPR6Im15DMTB39NlfdTY9BQfieANPBjdg/aVNwY=
10401040
github.com/pion/turn/v2 v2.0.6/go.mod h1:+y7xl719J8bAEVpSXBXvTxStjJv3hbz9YFflvkpcGPw=
10411041
github.com/pion/udp v0.1.1 h1:8UAPvyqmsxK8oOjloDk4wUt63TzFe9WEJkg5lChlj7o=
10421042
github.com/pion/udp v0.1.1/go.mod h1:6AFo+CMdKQm7UiA0eUPA8/eVCTx8jBIITLZHc9DWX5M=
1043-
github.com/pion/webrtc/v3 v3.1.19 h1:a4mrYskJE9LLUEogSnYVBna0Plg+fwwGLkDraz1WSwI=
1044-
github.com/pion/webrtc/v3 v3.1.19/go.mod h1:JRlX2EANa0bbyNzbqhkSiio+tT284fgco03Xw+aS/4Q=
1043+
github.com/pion/webrtc/v3 v3.1.21 h1:6b/65m5hSw2mF+sssHBx7Q2WPccklA0U0veEYtqZSuM=
1044+
github.com/pion/webrtc/v3 v3.1.21/go.mod h1:dIT2ETlP5dnlkgp46fAH56UizvOKuXJ9ySgFkhtmBbw=
10451045
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
10461046
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
10471047
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -1422,8 +1422,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
14221422
golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
14231423
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
14241424
golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1425-
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba h1:6u6sik+bn/y7vILcYkK3iwTBWN7WtBvB0+SZswQnbf8=
1426-
golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
1425+
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
1426+
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
14271427
golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
14281428
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
14291429
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=

peer/conn.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -145,39 +145,39 @@ func (c *Conn) init() error {
145145

146146
c.rtc.OnNegotiationNeeded(c.negotiate)
147147
c.rtc.OnICEConnectionStateChange(func(iceConnectionState webrtc.ICEConnectionState) {
148-
if c.isClosed() {
148+
c.closedICEMutex.Lock()
149+
defer c.closedICEMutex.Unlock()
150+
select {
151+
case <-c.closedICE:
152+
// Don't log more state changes if we've already closed.
149153
return
150-
}
151-
152-
c.opts.Logger.Debug(context.Background(), "ice connection state updated",
153-
slog.F("state", iceConnectionState))
154+
default:
155+
c.opts.Logger.Debug(context.Background(), "ice connection state updated",
156+
slog.F("state", iceConnectionState))
154157

155-
if iceConnectionState == webrtc.ICEConnectionStateClosed {
156-
// pion/webrtc can update this state multiple times.
157-
// A connection can never become un-closed, so we
158-
// close the channel if it isn't already.
159-
c.closedICEMutex.Lock()
160-
defer c.closedICEMutex.Unlock()
161-
select {
162-
case <-c.closedICE:
163-
default:
158+
if iceConnectionState == webrtc.ICEConnectionStateClosed {
159+
// pion/webrtc can update this state multiple times.
160+
// A connection can never become un-closed, so we
161+
// close the channel if it isn't already.
164162
close(c.closedICE)
165163
}
166164
}
167165
})
168166
c.rtc.OnICEGatheringStateChange(func(iceGatherState webrtc.ICEGathererState) {
169-
c.opts.Logger.Debug(context.Background(), "ice gathering state updated",
170-
slog.F("state", iceGatherState))
167+
c.closedICEMutex.Lock()
168+
defer c.closedICEMutex.Unlock()
169+
select {
170+
case <-c.closedICE:
171+
// Don't log more state changes if we've already closed.
172+
return
173+
default:
174+
c.opts.Logger.Debug(context.Background(), "ice gathering state updated",
175+
slog.F("state", iceGatherState))
171176

172-
if iceGatherState == webrtc.ICEGathererStateClosed {
173-
// pion/webrtc can update this state multiple times.
174-
// A connection can never become un-closed, so we
175-
// close the channel if it isn't already.
176-
c.closedICEMutex.Lock()
177-
defer c.closedICEMutex.Unlock()
178-
select {
179-
case <-c.closedICE:
180-
default:
177+
if iceGatherState == webrtc.ICEGathererStateClosed {
178+
// pion/webrtc can update this state multiple times.
179+
// A connection can never become un-closed, so we
180+
// close the channel if it isn't already.
181181
close(c.closedICE)
182182
}
183183
}
@@ -292,7 +292,7 @@ func (c *Conn) negotiate() {
292292
_ = c.CloseWithError(xerrors.Errorf("set local description: %w", err))
293293
return
294294
}
295-
c.opts.Logger.Debug(context.Background(), "sending offer")
295+
c.opts.Logger.Debug(context.Background(), "sending offer", slog.F("offer", offer))
296296
select {
297297
case <-c.closed:
298298
return
@@ -331,7 +331,7 @@ func (c *Conn) negotiate() {
331331
_ = c.CloseWithError(xerrors.Errorf("set local description: %w", err))
332332
return
333333
}
334-
c.opts.Logger.Debug(context.Background(), "sending answer")
334+
c.opts.Logger.Debug(context.Background(), "sending answer", slog.F("answer", answer))
335335
select {
336336
case <-c.closed:
337337
return

0 commit comments

Comments
 (0)