Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 5446c03

Browse files
authored
Merge pull request #25 from hertz-contrib/fix/cli-conn-close
fix(client): keep ref to resp to avoid conn closed
2 parents 193c8be + 7e35697 commit 5446c03

9 files changed

Lines changed: 73 additions & 76 deletions

File tree

.github/workflows/pr-check.yml

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
11
name: Pull Request Check
22

3-
on: [pull_request]
3+
on: [ pull_request ]
44

55
jobs:
66
compliant:
7-
runs-on: self-hosted
7+
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010

1111
- name: Check License Header
12-
uses: apache/skywalking-eyes@header@v0.4.0
12+
uses: apache/skywalking-eyes/header@v0.4.0
1313
env:
1414
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1515

16-
- name: typos-action
16+
- name: Check Spell
1717
uses: crate-ci/typos@master
1818

19-
staticcheck:
20-
runs-on: self-hosted
19+
golangci-lint:
20+
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v3
23-
22+
- uses: actions/checkout@v4
2423
- name: Set up Go
25-
uses: actions/setup-go@v3
26-
with:
27-
go-version: 1.16
28-
29-
- uses: actions/cache@v3
24+
uses: actions/setup-go@v5
3025
with:
31-
path: ~/go/pkg/mod
32-
key: reviewdog-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
33-
restore-keys: |
34-
reviewdog-${{ runner.os }}-go-
35-
36-
- uses: reviewdog/action-staticcheck@v1
26+
go-version: stable
27+
# for self-hosted, the cache path is shared across projects
28+
# and it works well without the cache of github actions
29+
# Enable it if we're going to use Github only
30+
cache: true
31+
32+
- name: Golangci Lint
33+
# https://golangci-lint.run/
34+
uses: golangci/golangci-lint-action@v6
3735
with:
38-
github_token: ${{ secrets.github_token }}
39-
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
40-
reporter: github-pr-review
41-
# Report all results.
42-
filter_mode: nofilter
43-
# Exit with 1 when it find at least one finding.
44-
fail_on_error: true
45-
# Set staticcheck flags
46-
staticcheck_flags: -checks=inherit,-SA1029,-SA6002
36+
version: latest

.github/workflows/release-check.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
name: Tests
22

3-
on: [push, pull_request]
3+
on: [ push, pull_request ]
44

55
jobs:
6-
lint-and-ut:
7-
runs-on: self-hosted
6+
benchmark:
7+
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
10-
9+
- uses: actions/checkout@v4
1110
- name: Set up Go
12-
uses: actions/setup-go@v3
13-
with:
14-
go-version: 1.18
15-
16-
- uses: actions/cache@v3
11+
uses: actions/setup-go@v5
1712
with:
18-
path: ~/go/pkg/mod
19-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
20-
restore-keys: |
21-
${{ runner.os }}-go-
13+
go-version: stable
2214

23-
- name: Lint
24-
run: |
25-
go vet -stdmethods=false $(go list ./...)
26-
go install mvdan.cc/gofumpt@v0.2.0
27-
test -z "$(gofumpt -l -extra .)"
15+
- name: Benchmark
16+
run: go test -bench=. -benchmem ./...
2817

18+
uinttest:
19+
strategy:
20+
matrix:
21+
go: [ "1.18", "1.19", "1.20", "1.21", "1.22", "1.23" ]
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: ${{ matrix.go }}
29+
cache: true # set false for self-hosted
2930
- name: Unit Test
30-
run: go test -race -covermode=atomic -coverprofile=coverage.out ./...
31+
run: go test -race ./...

.golangci.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
linters: # https://golangci-lint.run/usage/linters/
2+
disable-all: true
3+
enable:
4+
# - errcheck # can not skip _test.go ?
5+
- gosimple
6+
- govet
7+
- ineffassign
8+
- staticcheck
9+
- unused
10+
- unconvert

client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// This file may have been modified by CloudWeGo authors. All CloudWeGo
6+
// Modifications are Copyright 2022 CloudWeGo Authors.
7+
18
package websocket
29

310
import (
@@ -86,5 +93,6 @@ func (p *ClientUpgrader) UpgradeResponse(req *protocol.Request, resp *protocol.R
8693
conn.newCompressionWriter = compressNoContextTakeover
8794
conn.newDecompressionReader = decompressNoContextTakeover
8895
}
96+
conn.resp = resp
8997
return conn, nil
9098
}

client_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// This file may have been modified by CloudWeGo authors. All CloudWeGo
6+
// Modifications are Copyright 2022 CloudWeGo Authors.
7+
18
package websocket
29

310
import (

conn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ type Conn struct {
282282

283283
readDecompress bool // whether last read frame had RSV1 set
284284
newDecompressionReader func(io.Reader) io.ReadCloser
285+
286+
// keep reference to the resp to make sure the underlying conn will not be closed.
287+
// see: https://github.com/cloudwego/hertz/pull/1214 for the details.
288+
resp interface{} // *protocol.Response
285289
}
286290

287291
func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, writeBufferPool BufferPool, br *bufio.Reader, writeBuf []byte) *Conn {

conn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestFraming(t *testing.T) {
8686
return w.Write(writeBuf[:n])
8787
}},
8888
{"string", func(w io.Writer, n int) (int, error) {
89-
return io.WriteString(w, string(writeBuf[:n]))
89+
return io.WriteString(w, string(writeBuf[:n])) // nolint: staticcheck
9090
}},
9191
}
9292

server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ func (u *HertzUpgrader) Upgrade(ctx *app.RequestContext, handler HertzHandler) e
211211
handler(c)
212212

213213
writeBuf = writeBuf[0:0]
214-
poolWriteBuffer.Put(writeBuf)
214+
215+
// FIXME: argument should be pointer-like to avoid allocations (staticcheck)
216+
poolWriteBuffer.Put(writeBuf) // nolint: staticcheck
215217
})
216218

217219
return nil

0 commit comments

Comments
 (0)