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

Commit1fa50a9

Browse files
authored
fix: Race when writing to a closed pipe (#1916)
1 parent1c5d94e commit1fa50a9

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

‎provisionersdk/serve.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Serve(ctx context.Context, server proto.DRPCProvisionerServer, options *Ser
3131
ifoptions.Listener==nil {
3232
config:=yamux.DefaultConfig()
3333
config.LogOutput=io.Discard
34-
stdio,err:=yamux.Server(readWriteCloser{
34+
stdio,err:=yamux.Server(&readWriteCloser{
3535
ReadCloser:os.Stdin,
3636
Writer:os.Stdout,
3737
},config)
@@ -54,6 +54,9 @@ func Serve(ctx context.Context, server proto.DRPCProvisionerServer, options *Ser
5454
// short-lived processes that can be executed concurrently.
5555
err=srv.Serve(ctx,options.Listener)
5656
iferr!=nil {
57+
iferrors.Is(err,io.EOF) {
58+
returnnil
59+
}
5760
iferrors.Is(err,context.Canceled) {
5861
returnnil
5962
}
@@ -67,3 +70,8 @@ func Serve(ctx context.Context, server proto.DRPCProvisionerServer, options *Ser
6770
}
6871
returnnil
6972
}
73+
74+
typereadWriteCloserstruct {
75+
io.ReadCloser
76+
io.Writer
77+
}

‎provisionersdk/transport.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provisionersdk
33
import (
44
"context"
55
"io"
6+
"net"
67

78
"github.com/hashicorp/yamux"
89
"storj.io/drpc"
@@ -17,22 +18,14 @@ const (
1718

1819
// TransportPipe creates an in-memory pipe for dRPC transport.
1920
funcTransportPipe() (*yamux.Session,*yamux.Session) {
20-
clientReader,clientWriter:=io.Pipe()
21-
serverReader,serverWriter:=io.Pipe()
21+
c1,c2:=net.Pipe()
2222
yamuxConfig:=yamux.DefaultConfig()
2323
yamuxConfig.LogOutput=io.Discard
24-
client,err:=yamux.Client(&readWriteCloser{
25-
ReadCloser:clientReader,
26-
Writer:serverWriter,
27-
},yamuxConfig)
24+
client,err:=yamux.Client(c1,yamuxConfig)
2825
iferr!=nil {
2926
panic(err)
3027
}
31-
32-
server,err:=yamux.Server(&readWriteCloser{
33-
ReadCloser:serverReader,
34-
Writer:clientWriter,
35-
},yamuxConfig)
28+
server,err:=yamux.Server(c2,yamuxConfig)
3629
iferr!=nil {
3730
panic(err)
3831
}
@@ -44,11 +37,6 @@ func Conn(session *yamux.Session) drpc.Conn {
4437
return&multiplexedDRPC{session}
4538
}
4639

47-
typereadWriteCloserstruct {
48-
io.ReadCloser
49-
io.Writer
50-
}
51-
5240
// Allows concurrent requests on a single dRPC connection.
5341
// Required for calling functions concurrently.
5442
typemultiplexedDRPCstruct {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp