Skip to content

Commit 8a6704c

Browse files
committed
Merge branch 'master' into FrauElster/master
2 parents c3613fc + 1253b77 commit 8a6704c

File tree

13 files changed

+127
-111
lines changed

13 files changed

+127
-111
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/dependabot.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: 2
2+
updates:
3+
# Track in case we ever add dependencies.
4+
- package-ecosystem: 'gomod'
5+
directory: '/'
6+
schedule:
7+
interval: 'weekly'
8+
commit-message:
9+
prefix: 'chore'
10+
11+
# Keep example and test/benchmark deps up-to-date.
12+
- package-ecosystem: 'gomod'
13+
directories:
14+
- '/internal/examples'
15+
- '/internal/thirdparty'
16+
schedule:
17+
interval: 'monthly'
18+
commit-message:
19+
prefix: 'chore'
20+
labels: []
21+
groups:
22+
internal-deps:
23+
patterns:
24+
- '*'

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
name: ci
2-
on: [push, pull_request]
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
39
concurrency:
410
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
511
cancel-in-progress: true

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ http.HandlerFunc(func (w http.ResponseWriter, r *http.Request) {
6363
}
6464
defer c.CloseNow()
6565

66-
ctx, cancel := context.WithTimeout(r.Context(), time.Second*10)
66+
// Set the context as needed. Use of r.Context() is not recommended
67+
// to avoid surprising behavior (see http.Hijacker).
68+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
6769
defer cancel()
6870

6971
var v interface{}

accept.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func (opts *AcceptOptions) cloneWithDefaults() *AcceptOptions {
7979
// See the InsecureSkipVerify and OriginPatterns options to allow cross origin requests.
8080
//
8181
// Accept will write a response to w on all errors.
82+
//
83+
// Note that using the http.Request Context after Accept returns may lead to
84+
// unexpected behavior (see http.Hijacker).
8285
func Accept(w http.ResponseWriter, r *http.Request, opts *AcceptOptions) (*Conn, error) {
8386
return accept(w, r, opts)
8487
}

ci/fmt.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
set -eu
33
cd -- "$(dirname "$0")/.."
44

5+
# Pin golang.org/x/tools, the go.mod of v0.25.0 is incompatible with Go 1.19.
6+
X_TOOLS_VERSION=v0.24.0
7+
58
go mod tidy
69
(cd ./internal/thirdparty && go mod tidy)
710
(cd ./internal/examples && go mod tidy)
811
gofmt -w -s .
9-
go run golang.org/x/tools/cmd/goimports@latest -w "-local=$(go list -m)" .
12+
go run golang.org/x/tools/cmd/goimports@${X_TOOLS_VERSION} -w "-local=$(go list -m)" .
1013

11-
npx prettier@3.0.3 \
12-
--write \
14+
git ls-files "*.yml" "*.md" "*.js" "*.css" "*.html" | xargs npx prettier@3.3.3 \
15+
--check \
1316
--log-level=warn \
1417
--print-width=90 \
1518
--no-semi \
1619
--single-quote \
17-
--arrow-parens=avoid \
18-
$(git ls-files "*.yml" "*.md" "*.js" "*.css" "*.html")
20+
--arrow-parens=avoid
1921

20-
go run golang.org/x/tools/cmd/stringer@latest -type=opcode,MessageType,StatusCode -output=stringer.go
22+
go run golang.org/x/tools/cmd/stringer@${X_TOOLS_VERSION} -type=opcode,MessageType,StatusCode -output=stringer.go
2123

2224
if [ "${CI-}" ]; then
2325
git diff --exit-code

internal/examples/chat/chat.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (cs *chatServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7070
// subscribeHandler accepts the WebSocket connection and then subscribes
7171
// it to all future messages.
7272
func (cs *chatServer) subscribeHandler(w http.ResponseWriter, r *http.Request) {
73-
err := cs.subscribe(r.Context(), w, r)
73+
err := cs.subscribe(w, r)
7474
if errors.Is(err, context.Canceled) {
7575
return
7676
}
@@ -111,7 +111,7 @@ func (cs *chatServer) publishHandler(w http.ResponseWriter, r *http.Request) {
111111
//
112112
// It uses CloseRead to keep reading from the connection to process control
113113
// messages and cancel the context if the connection drops.
114-
func (cs *chatServer) subscribe(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
114+
func (cs *chatServer) subscribe(w http.ResponseWriter, r *http.Request) error {
115115
var mu sync.Mutex
116116
var c *websocket.Conn
117117
var closed bool
@@ -142,7 +142,7 @@ func (cs *chatServer) subscribe(ctx context.Context, w http.ResponseWriter, r *h
142142
mu.Unlock()
143143
defer c.CloseNow()
144144

145-
ctx = c.CloseRead(ctx)
145+
ctx := c.CloseRead(context.Background())
146146

147147
for {
148148
select {

internal/examples/chat/chat_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Test_chatServer(t *testing.T) {
5252
// 10 clients are started that send 128 different
5353
// messages of max 128 bytes concurrently.
5454
//
55-
// The test verifies that every message is seen by ever client
55+
// The test verifies that every message is seen by every client
5656
// and no errors occur anywhere.
5757
t.Run("concurrency", func(t *testing.T) {
5858
t.Parallel()

internal/examples/echo/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (s echoServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
3737

3838
l := rate.NewLimiter(rate.Every(time.Millisecond*100), 10)
3939
for {
40-
err = echo(r.Context(), c, l)
40+
err = echo(c, l)
4141
if websocket.CloseStatus(err) == websocket.StatusNormalClosure {
4242
return
4343
}
@@ -51,8 +51,8 @@ func (s echoServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
5151
// echo reads from the WebSocket connection and then writes
5252
// the received message back to it.
5353
// The entire function has 10s to complete.
54-
func echo(ctx context.Context, c *websocket.Conn, l *rate.Limiter) error {
55-
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
54+
func echo(c *websocket.Conn, l *rate.Limiter) error {
55+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
5656
defer cancel()
5757

5858
err := l.Wait(ctx)

internal/examples/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ replace github.com/coder/websocket => ../..
66

77
require (
88
github.com/coder/websocket v0.0.0-00010101000000-000000000000
9-
golang.org/x/time v0.3.0
9+
golang.org/x/time v0.7.0
1010
)

0 commit comments

Comments
 (0)