change flag from RDONLY to RDWR and close the fifo correct

Signed-off-by: Zhiyu Li <payall4u@qq.com>
This commit is contained in:
payall4u 2021-01-31 12:43:40 +08:00
parent 20346607b9
commit 957fa3379d
3 changed files with 15 additions and 4 deletions

View File

@ -115,6 +115,7 @@ func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_
onCloseWithShimLog := func() { onCloseWithShimLog := func() {
onClose() onClose()
cancelShimLog() cancelShimLog()
f.Close()
} }
client := ttrpc.NewClient(conn, ttrpc.WithOnClose(onCloseWithShimLog)) client := ttrpc.NewClient(conn, ttrpc.WithOnClose(onCloseWithShimLog))
return &shim{ return &shim{

View File

@ -76,7 +76,13 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
conn.Close() conn.Close()
} }
}() }()
f, err := openShimLog(ctx, bundle, client.AnonReconnectDialer) shimCtx, cancelShimLog := context.WithCancel(ctx)
defer func() {
if err != nil {
cancelShimLog()
}
}()
f, err := openShimLog(shimCtx, bundle, client.AnonReconnectDialer)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "open shim log pipe") return nil, errors.Wrap(err, "open shim log pipe")
} }
@ -99,8 +105,12 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
} }
} }
}() }()
onCloseWithShimLog := func() {
client := ttrpc.NewClient(conn, ttrpc.WithOnClose(onClose)) onClose()
cancelShimLog()
f.Close()
}
client := ttrpc.NewClient(conn, ttrpc.WithOnClose(onCloseWithShimLog))
defer func() { defer func() {
if err != nil { if err != nil {
client.Close() client.Close()

View File

@ -30,7 +30,7 @@ import (
) )
func openShimLog(ctx context.Context, bundle *Bundle, _ func(string, time.Duration) (net.Conn, error)) (io.ReadCloser, error) { func openShimLog(ctx context.Context, bundle *Bundle, _ func(string, time.Duration) (net.Conn, error)) (io.ReadCloser, error) {
return fifo.OpenFifo(ctx, filepath.Join(bundle.Path, "log"), unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700) return fifo.OpenFifo(ctx, filepath.Join(bundle.Path, "log"), unix.O_RDWR|unix.O_CREAT|unix.O_NONBLOCK, 0700)
} }
func checkCopyShimLogError(ctx context.Context, err error) error { func checkCopyShimLogError(ctx context.Context, err error) error {