From 700fae5e00bb5e5630ab06595f6a436396e7ac12 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 12 Mar 2020 18:56:04 +0100 Subject: [PATCH] Call coredor (via gRPC) with independent context & timeout Reusing context caused random case of context cancelation on server side and "illegal buffer" error on corredor --- pkg/corredor/service.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/corredor/service.go b/pkg/corredor/service.go index 5c6a3cc10..bcc070377 100644 --- a/pkg/corredor/service.go +++ b/pkg/corredor/service.go @@ -502,6 +502,8 @@ func (svc *service) registerTriggers(script *ServerScript) []uintptr { // individual event implemntation func (svc service) exec(ctx context.Context, script string, runAs string, event Event) (err error) { var ( + requestId = middleware.GetReqID(ctx) + rsp *ExecResponse invoker auth.Identifiable @@ -604,13 +606,19 @@ func (svc service) exec(ctx context.Context, script string, runAs string, event // //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// - ctx, cancel := context.WithTimeout(ctx, svc.opt.DefaultExecTimeout) + ctx, cancel := context.WithTimeout( + // We need a new, independent context here + // to be sure this is executed safely & fully + // without any outside interfeance (cancellation, timeouts) + context.Background(), + svc.opt.DefaultExecTimeout, + ) defer cancel() // //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// ctx = metadata.NewOutgoingContext(ctx, metadata.MD{ - "x-request-id": []string{middleware.GetReqID(ctx)}, + "x-request-id": []string{requestId}, }) // //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// //// ////