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

fix: Race when writing to a closed pipe#1916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kylecarbs merged 1 commit intomainfromreadclose
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletionprovisionersdk/serve.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ func Serve(ctx context.Context, server proto.DRPCProvisionerServer, options *Ser
ifoptions.Listener==nil {
config:=yamux.DefaultConfig()
config.LogOutput=io.Discard
stdio,err:=yamux.Server(readWriteCloser{
stdio,err:=yamux.Server(&readWriteCloser{
ReadCloser:os.Stdin,
Writer:os.Stdout,
},config)
Expand All@@ -54,6 +54,9 @@ func Serve(ctx context.Context, server proto.DRPCProvisionerServer, options *Ser
// short-lived processes that can be executed concurrently.
err=srv.Serve(ctx,options.Listener)
iferr!=nil {
iferrors.Is(err,io.EOF) {
returnnil
}
iferrors.Is(err,context.Canceled) {
returnnil
}
Expand All@@ -67,3 +70,8 @@ func Serve(ctx context.Context, server proto.DRPCProvisionerServer, options *Ser
}
returnnil
}

typereadWriteCloserstruct {
io.ReadCloser
io.Writer
}
20 changes: 4 additions & 16 deletionsprovisionersdk/transport.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package provisionersdk
import (
"context"
"io"
"net"

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

// TransportPipe creates an in-memory pipe for dRPC transport.
func TransportPipe() (*yamux.Session, *yamux.Session) {
clientReader, clientWriter := io.Pipe()
serverReader, serverWriter := io.Pipe()
c1, c2 := net.Pipe()
yamuxConfig := yamux.DefaultConfig()
yamuxConfig.LogOutput = io.Discard
client, err := yamux.Client(&readWriteCloser{
ReadCloser: clientReader,
Writer: serverWriter,
}, yamuxConfig)
client, err := yamux.Client(c1, yamuxConfig)
if err != nil {
panic(err)
}

server, err := yamux.Server(&readWriteCloser{
ReadCloser: serverReader,
Writer: clientWriter,
}, yamuxConfig)
server, err := yamux.Server(c2, yamuxConfig)
if err != nil {
panic(err)
}
Expand All@@ -44,11 +37,6 @@ func Conn(session *yamux.Session) drpc.Conn {
return &multiplexedDRPC{session}
}

type readWriteCloser struct {
io.ReadCloser
io.Writer
}

// Allows concurrent requests on a single dRPC connection.
// Required for calling functions concurrently.
type multiplexedDRPC struct {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp