From 957fa3379da878817f695d057ae50b127f81e32a Mon Sep 17 00:00:00 2001 From: payall4u Date: Sun, 31 Jan 2021 12:43:40 +0800 Subject: [PATCH] change flag from RDONLY to RDWR and close the fifo correct Signed-off-by: Zhiyu Li --- runtime/v2/binary.go | 1 + runtime/v2/shim.go | 16 +++++++++++++--- runtime/v2/shim_unix.go | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/runtime/v2/binary.go b/runtime/v2/binary.go index 4b3f4ab93..49ecd80e9 100644 --- a/runtime/v2/binary.go +++ b/runtime/v2/binary.go @@ -115,6 +115,7 @@ func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_ onCloseWithShimLog := func() { onClose() cancelShimLog() + f.Close() } client := ttrpc.NewClient(conn, ttrpc.WithOnClose(onCloseWithShimLog)) return &shim{ diff --git a/runtime/v2/shim.go b/runtime/v2/shim.go index 9a6b0ec70..7dc218dd2 100644 --- a/runtime/v2/shim.go +++ b/runtime/v2/shim.go @@ -76,7 +76,13 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt 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 { return nil, errors.Wrap(err, "open shim log pipe") } @@ -99,8 +105,12 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt } } }() - - client := ttrpc.NewClient(conn, ttrpc.WithOnClose(onClose)) + onCloseWithShimLog := func() { + onClose() + cancelShimLog() + f.Close() + } + client := ttrpc.NewClient(conn, ttrpc.WithOnClose(onCloseWithShimLog)) defer func() { if err != nil { client.Close() diff --git a/runtime/v2/shim_unix.go b/runtime/v2/shim_unix.go index 16e9c7be3..898839bd4 100644 --- a/runtime/v2/shim_unix.go +++ b/runtime/v2/shim_unix.go @@ -30,7 +30,7 @@ import ( ) 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 {