Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit7f0e87d

Browse files
authored
fix: Increase ICE timeouts (#392)
* fix: Increase ICE timeouts* Fix ping times
1 parent08fe800 commit7f0e87d

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

‎wsnet/dial.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ type Dialer struct {
137137
closedChanchanstruct{}
138138
connClosers []io.Closer
139139
connClosersMut sync.Mutex
140+
pingMut sync.Mutex
140141
}
141142

142143
func (d*Dialer)negotiate() (errerror) {
@@ -160,7 +161,7 @@ func (d *Dialer) negotiate() (err error) {
160161
return
161162
}
162163
d.rtc.OnConnectionStateChange(func(pcs webrtc.PeerConnectionState) {
163-
ifpcs==webrtc.PeerConnectionStateConnected {
164+
ifpcs!=webrtc.PeerConnectionStateDisconnected {
164165
return
165166
}
166167

@@ -178,6 +179,7 @@ func (d *Dialer) negotiate() (err error) {
178179
default:
179180
}
180181
close(d.closedChan)
182+
_=d.rtc.Close()
181183
})
182184
}()
183185

@@ -263,7 +265,7 @@ func (d *Dialer) Ping(ctx context.Context) error {
263265
// Since we control the client and server we could open this
264266
// data channel with `Negotiated` true to reduce traffic being
265267
// sent when the RTC connection is opened.
266-
err:=waitForDataChannelOpen(context.Background(),d.ctrl)
268+
err:=waitForDataChannelOpen(ctx,d.ctrl)
267269
iferr!=nil {
268270
returnerr
269271
}
@@ -273,13 +275,28 @@ func (d *Dialer) Ping(ctx context.Context) error {
273275
returnerr
274276
}
275277
}
278+
d.pingMut.Lock()
279+
deferd.pingMut.Unlock()
276280
_,err=d.ctrlrw.Write([]byte{'a'})
277281
iferr!=nil {
278282
returnfmt.Errorf("write: %w",err)
279283
}
280-
b:=make([]byte,4)
281-
_,err=d.ctrlrw.Read(b)
282-
returnerr
284+
errCh:=make(chanerror)
285+
gofunc() {
286+
// There's a race in which connections can get lost-mid ping
287+
// in which case this would block forever.
288+
deferclose(errCh)
289+
_,err=d.ctrlrw.Read(make([]byte,4))
290+
errCh<-err
291+
}()
292+
ctx,cancelFunc:=context.WithTimeout(ctx,time.Second*15)
293+
defercancelFunc()
294+
select {
295+
caseerr:=<-errCh:
296+
returnerr
297+
case<-ctx.Done():
298+
returnctx.Err()
299+
}
283300
}
284301

285302
// DialContext dials the network and address on the remote listener.

‎wsnet/rtc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ func newPeerConnection(servers []webrtc.ICEServer, dialer proxy.Dialer) (*webrtc
160160
se.SetNetworkTypes([]webrtc.NetworkType{webrtc.NetworkTypeUDP4})
161161
se.SetSrflxAcceptanceMinWait(0)
162162
se.DetachDataChannels()
163-
se.SetICETimeouts(time.Second*3,time.Second*3,time.Second*2)
163+
// If the disconnect and keep-alive timeouts are too closely related, we'll
164+
// experience "random" connection failures.
165+
se.SetICETimeouts(time.Second*5,time.Second*25,time.Second*2)
164166
lf:=logging.NewDefaultLoggerFactory()
165167
lf.DefaultLogLevel=logging.LogLevelDisabled
166168
se.LoggerFactory=lf

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp