internal/poll:add SPLICE_F_NONBLOCK flag for splice to avoid insonsistency with O_NONBLOC
internal/poll:add SPLICE_F_NONBLOCK flag for splice to avoid insonsistency with O_NONBLOC Signed-off-by: EulerOSWander <314264452@qq.com> (cherry picked from commit 1e4bf241308377399305e37d1993066ca37baaa7)
This commit is contained in:
parent
3e4e38218c
commit
34ef1309b1
@ -0,0 +1,79 @@
|
||||
From fef8644451930464ffd9f13c82bcd451f58fa575 Mon Sep 17 00:00:00 2001
|
||||
From: Andy Pan <panjf2000@gmail.com>
|
||||
Date: Tue, 17 Oct 2023 22:38:17 +0800
|
||||
Subject: [PATCH 03/20] [release-branch.go1.21] internal/poll: add
|
||||
SPLICE_F_NONBLOCK flag for splice to avoid inconsistency with O_NONBLOCK
|
||||
|
||||
Fixes #63801
|
||||
Updates #59041
|
||||
Updates #63795
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://go-review.googlesource.com/c/go/+/536015
|
||||
|
||||
Details: https://github.com/golang/go/issues/59041#issuecomment-1766610087
|
||||
|
||||
Change-Id: Id3fc1df6d86b7c4cc383d09f9465fa8f4cc2a559
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/536015
|
||||
Reviewed-by: Bryan Mills <bcmills@google.com>
|
||||
Reviewed-by: Ian Lance Taylor <iant@google.com>
|
||||
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
|
||||
Auto-Submit: Ian Lance Taylor <iant@google.com>
|
||||
(cherry picked from commit 40cdf69fc9279ab28f84a6e0f965de8382c578fe)
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/538117
|
||||
Auto-Submit: Heschi Kreinick <heschi@google.com>
|
||||
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
|
||||
Reviewed-by: Heschi Kreinick <heschi@google.com>
|
||||
---
|
||||
src/internal/poll/splice_linux.go | 21 +++++++++++++++++++--
|
||||
1 file changed, 19 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/internal/poll/splice_linux.go b/src/internal/poll/splice_linux.go
|
||||
index 9505c5dcfc1e..72cca34fe4ae 100644
|
||||
--- a/src/internal/poll/splice_linux.go
|
||||
+++ b/src/internal/poll/splice_linux.go
|
||||
@@ -13,6 +13,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
+ // spliceNonblock doesn't make the splice itself necessarily nonblocking
|
||||
+ // (because the actual file descriptors that are spliced from/to may block
|
||||
+ // unless they have the O_NONBLOCK flag set), but it makes the splice pipe
|
||||
+ // operations nonblocking.
|
||||
+ spliceNonblock = 0x2
|
||||
+
|
||||
// maxSpliceSize is the maximum amount of data Splice asks
|
||||
// the kernel to move in a single call to splice(2).
|
||||
// We use 1MB as Splice writes data through a pipe, and 1MB is the default maximum pipe buffer size,
|
||||
@@ -89,7 +95,11 @@ func spliceDrain(pipefd int, sock *FD, max int) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
for {
|
||||
- n, err := splice(pipefd, sock.Sysfd, max, 0)
|
||||
+ // In theory calling splice(2) with SPLICE_F_NONBLOCK could end up an infinite loop here,
|
||||
+ // because it could return EAGAIN ceaselessly when the write end of the pipe is full,
|
||||
+ // but this shouldn't be a concern here, since the pipe buffer must be sufficient for
|
||||
+ // this data transmission on the basis of the workflow in Splice.
|
||||
+ n, err := splice(pipefd, sock.Sysfd, max, spliceNonblock)
|
||||
if err == syscall.EINTR {
|
||||
continue
|
||||
}
|
||||
@@ -127,7 +137,14 @@ func splicePump(sock *FD, pipefd int, inPipe int) (int, error) {
|
||||
}
|
||||
written := 0
|
||||
for inPipe > 0 {
|
||||
- n, err := splice(sock.Sysfd, pipefd, inPipe, 0)
|
||||
+ // In theory calling splice(2) with SPLICE_F_NONBLOCK could end up an infinite loop here,
|
||||
+ // because it could return EAGAIN ceaselessly when the read end of the pipe is empty,
|
||||
+ // but this shouldn't be a concern here, since the pipe buffer must contain inPipe size of
|
||||
+ // data on the basis of the workflow in Splice.
|
||||
+ n, err := splice(sock.Sysfd, pipefd, inPipe, spliceNonblock)
|
||||
+ if err == syscall.EINTR {
|
||||
+ continue
|
||||
+ }
|
||||
// Here, the condition n == 0 && err == nil should never be
|
||||
// observed, since Splice controls the write side of the pipe.
|
||||
if n > 0 {
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -66,7 +66,7 @@
|
||||
|
||||
Name: golang
|
||||
Version: 1.21.4
|
||||
Release: 17
|
||||
Release: 18
|
||||
Summary: The Go Programming Language
|
||||
License: BSD and Public Domain
|
||||
URL: https://golang.org/
|
||||
@ -136,6 +136,7 @@ Patch6012: backport-0012-net-http-send-body-or-close-connection-on-expect-100.pa
|
||||
Patch6013: backport-0013-release-branch.go1.21-net-http-update-bundled-golang.patch
|
||||
Patch6014: backport-0014-cmd-compile-handle-constant-pointer-offsets-in-dead-.patch
|
||||
Patch6015: backport-0015-release-branch.go1.21-cmd-compile-ensure-pointer-ari.patch
|
||||
Patch6016: backport-0016-release-branch.go1.21-internal-poll-add-SPLICE_F_NON.patch
|
||||
|
||||
ExclusiveArch: %{golang_arches}
|
||||
|
||||
@ -374,6 +375,9 @@ fi
|
||||
%files devel -f go-tests.list -f go-misc.list -f go-src.list
|
||||
|
||||
%changelog
|
||||
* Thu Aug 1 2024 EulerOSWander <314264452@qq.com> - 1.21.4-18
|
||||
- internal/poll:add SPLICE_F_NONBLOCK flag for splice to avoid insonsistency with O_NONBLOCK
|
||||
|
||||
* Mon Jul 30 2024 jingxiaolu <lujingxiao@huawei.com> - 1.21.4-17
|
||||
- cmd/compile: ensure pointer arithmetic happens after the nil check
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user