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

Commit4c89550

Browse files
authored
fix: ensure error chan is buffered in (*Dialer).negotiate (#437)
1 parentd2df9e1 commit4c89550

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

‎wsnet/dial.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,20 @@ type Dialer struct {
193193
func (d*Dialer)negotiate(ctx context.Context) (errerror) {
194194
var (
195195
decoder=json.NewDecoder(d.conn)
196-
errCh=make(chanerror)
196+
errCh=make(chanerror,1)
197197
// If candidates are sent before an offer, we place them here.
198198
// We currently have no assurances to ensure this can't happen,
199199
// so it's better to buffer and process than fail.
200200
pendingCandidates= []webrtc.ICECandidateInit{}
201201
)
202202
gofunc() {
203203
deferclose(errCh)
204-
deferfunc() {
205-
_=d.conn.Close()
206-
}()
204+
deferfunc() {_=d.conn.Close() }()
207205

208206
err:=waitForConnectionOpen(context.Background(),d.rtc)
209207
iferr!=nil {
210208
d.log.Debug(ctx,"negotiation error",slog.Error(err))
211-
iferrors.Is(err,context.DeadlineExceeded) {
212-
_=d.conn.Close()
213-
}
209+
214210
errCh<-fmt.Errorf("wait for connection to open: %w",err)
215211
return
216212
}
@@ -331,23 +327,28 @@ func (d *Dialer) Ping(ctx context.Context) error {
331327
returnerr
332328
}
333329
}
330+
334331
d.pingMut.Lock()
335332
deferd.pingMut.Unlock()
333+
336334
d.log.Debug(ctx,"sending ping")
337335
_,err=d.ctrlrw.Write([]byte{'a'})
338336
iferr!=nil {
339337
returnfmt.Errorf("write: %w",err)
340338
}
341-
errCh:=make(chanerror)
339+
340+
errCh:=make(chanerror,1)
342341
gofunc() {
343342
// There's a race in which connections can get lost-mid ping
344343
// in which case this would block forever.
345344
deferclose(errCh)
346345
_,err=d.ctrlrw.Read(make([]byte,4))
347346
errCh<-err
348347
}()
349-
ctx,cancelFunc:=context.WithTimeout(ctx,time.Second*15)
350-
defercancelFunc()
348+
349+
ctx,cancel:=context.WithTimeout(ctx,time.Second*15)
350+
defercancel()
351+
351352
select {
352353
caseerr:=<-errCh:
353354
returnerr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp