Skip to content

Commit 6976588

Browse files
committed
add batchDiscard
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
1 parent ababa3f commit 6976588

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
os: [ubuntu-latest, macos-latest, windows-latest]
2828

2929
steps:
30-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
3131
with:
3232
path: src/github.com/containerd/ttrpc
3333
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
@@ -47,19 +47,19 @@ jobs:
4747
#
4848
project:
4949
name: Project Checks
50-
runs-on: ubuntu-22.04
50+
runs-on: ubuntu-latest
5151
timeout-minutes: 5
5252

5353
steps:
54-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
54+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5555
with:
5656
path: src/github.com/containerd/ttrpc
5757
fetch-depth: 25
5858
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
5959
with:
6060
go-version: ${{ env.GO_VERSION }}
6161

62-
- uses: containerd/project-checks@434a07157608eeaa1d5c8d4dd506154204cd9401 # v1.1.0
62+
- uses: containerd/project-checks@d7751f3c375b8fe4a84c02a068184ee4c1f59bc4 # v1.2.2
6363
with:
6464
working-directory: src/github.com/containerd/ttrpc
6565

@@ -78,7 +78,7 @@ jobs:
7878
timeout-minutes: 10
7979
steps:
8080

81-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
81+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
8282
with:
8383
path: src/github.com/containerd/ttrpc
8484
fetch-depth: 25
@@ -110,7 +110,7 @@ jobs:
110110
timeout-minutes: 5
111111
steps:
112112

113-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
113+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
114114
with:
115115
path: src/github.com/containerd/ttrpc
116116
fetch-depth: 25

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "runDockerd",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${workspaceFolder}"
13+
}
14+
]
15+
}

channel.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ func newChannel(conn net.Conn) *channel {
111111
}
112112
}
113113

114+
func batchDiscard(br *bufio.Reader, total int, batchSize int) (int, error) {
115+
var discarded int
116+
for discarded < total {
117+
needDiscard := total - discarded
118+
currentBatch := batchSize
119+
if needDiscard < currentBatch {
120+
currentBatch = needDiscard
121+
}
122+
123+
n, err := br.Discard(currentBatch)
124+
discarded += n
125+
126+
if err != nil {
127+
return discarded, err
128+
}
129+
}
130+
return discarded, nil
131+
}
132+
114133
// recv a message from the channel. The returned buffer contains the message.
115134
//
116135
// If a valid grpc status is returned, the message header
@@ -124,7 +143,7 @@ func (ch *channel) recv() (messageHeader, []byte, error) {
124143
}
125144

126145
if mh.Length > uint32(messageLengthMax) {
127-
if _, err := ch.br.Discard(int(mh.Length)); err != nil {
146+
if _, err := batchDiscard(ch.br, int(mh.Length), messageLengthMax); err != nil {
128147
return mh, nil, fmt.Errorf("failed to discard after receiving oversized message: %w", err)
129148
}
130149

0 commit comments

Comments
 (0)