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

Commit53e7c33

Browse files
authored
fix: Close conn if context deadline is exceeded (#395)
* fix: Close conn if context deadline is exceededPreviously the error occurred but never propogated due to blocking frommthe read loop in negotiate. Now, connection timeouts can properly occur.* Fixes
1 parent3e78729 commit53e7c33

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

‎wsnet/dial.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,16 @@ func (d *Dialer) negotiate(ctx context.Context) (err error) {
147147
// so it's better to buffer and process than fail.
148148
pendingCandidates= []webrtc.ICECandidateInit{}
149149
)
150-
151150
gofunc() {
152151
deferclose(errCh)
153152
deferfunc() {
154153
_=d.conn.Close()
155154
}()
156155
err:=waitForConnectionOpen(ctx,d.rtc)
157156
iferr!=nil {
157+
iferrors.Is(err,context.DeadlineExceeded) {
158+
_=d.conn.Close()
159+
}
158160
errCh<-err
159161
return
160162
}

‎wsnet/dial_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net"
1010
"strconv"
1111
"testing"
12+
"time"
1213

1314
"cdr.dev/slog/sloggers/slogtest"
1415
"github.com/pion/ice/v2"
@@ -51,6 +52,18 @@ func ExampleDial_basic() {
5152
}
5253

5354
funcTestDial(t*testing.T) {
55+
t.Run("Timeout",func(t*testing.T) {
56+
t.Parallel()
57+
58+
connectAddr,_:=createDumbBroker(t)
59+
60+
ctx,cancelFunc:=context.WithTimeout(context.Background(),time.Millisecond*50)
61+
defercancelFunc()
62+
dialer,err:=DialWebsocket(ctx,connectAddr,nil,nil)
63+
require.True(t,errors.Is(err,context.DeadlineExceeded))
64+
require.Error(t,dialer.conn.Close(),"already wrote close")
65+
})
66+
5467
t.Run("Ping",func(t*testing.T) {
5568
t.Parallel()
5669

‎wsnet/rtc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func waitForConnectionOpen(ctx context.Context, conn *webrtc.PeerConnection) err
256256
})
257257
<-ctx.Done()
258258
ifctx.Err()==context.DeadlineExceeded {
259-
returnctx.Err()
259+
returncontext.DeadlineExceeded
260260
}
261261
returnnil
262262
}

‎wsnet/wsnet_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ func createDumbBroker(t testing.TB) (connectAddr string, listenAddr string) {
6868
mut.Lock()
6969
defermut.Unlock()
7070
ifsess==nil {
71-
t.Error("listen not called")
71+
// We discard inbound to emulate a pubsub where we don't know if anyone
72+
// is listening on the other side.
73+
_,_=io.Copy(io.Discard,nc)
7274
return
7375
}
7476
oc,err:=sess.Open()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp