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

Commit2954cab

Browse files
coadlerdeansheather
authored andcommitted
fix: ensure error chan is buffered in (*Dialer).negotiate (#437)
(cherry picked from commit4c89550)(cherry picked from commitcb15635)
1 parent6091ce3 commit2954cab

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
@@ -192,24 +192,20 @@ type Dialer struct {
192192
func (d*Dialer)negotiate(ctx context.Context) (errerror) {
193193
var (
194194
decoder=json.NewDecoder(d.conn)
195-
errCh=make(chanerror)
195+
errCh=make(chanerror,1)
196196
// If candidates are sent before an offer, we place them here.
197197
// We currently have no assurances to ensure this can't happen,
198198
// so it's better to buffer and process than fail.
199199
pendingCandidates= []webrtc.ICECandidateInit{}
200200
)
201201
gofunc() {
202202
deferclose(errCh)
203-
deferfunc() {
204-
_=d.conn.Close()
205-
}()
203+
deferfunc() {_=d.conn.Close() }()
206204

207205
err:=waitForConnectionOpen(context.Background(),d.rtc)
208206
iferr!=nil {
209207
d.log.Debug(ctx,"negotiation error",slog.Error(err))
210-
iferrors.Is(err,context.DeadlineExceeded) {
211-
_=d.conn.Close()
212-
}
208+
213209
errCh<-fmt.Errorf("wait for connection to open: %w",err)
214210
return
215211
}
@@ -325,23 +321,28 @@ func (d *Dialer) Ping(ctx context.Context) error {
325321
returnerr
326322
}
327323
}
324+
328325
d.pingMut.Lock()
329326
deferd.pingMut.Unlock()
327+
330328
d.log.Debug(ctx,"sending ping")
331329
_,err=d.ctrlrw.Write([]byte{'a'})
332330
iferr!=nil {
333331
returnfmt.Errorf("write: %w",err)
334332
}
335-
errCh:=make(chanerror)
333+
334+
errCh:=make(chanerror,1)
336335
gofunc() {
337336
// There's a race in which connections can get lost-mid ping
338337
// in which case this would block forever.
339338
deferclose(errCh)
340339
_,err=d.ctrlrw.Read(make([]byte,4))
341340
errCh<-err
342341
}()
343-
ctx,cancelFunc:=context.WithTimeout(ctx,time.Second*15)
344-
defercancelFunc()
342+
343+
ctx,cancel:=context.WithTimeout(ctx,time.Second*15)
344+
defercancel()
345+
345346
select {
346347
caseerr:=<-errCh:
347348
returnerr

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp