From 34b74544deb69303bfc19ac2dfc176d2436e6fcf Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Mon, 26 Nov 2018 01:25:10 -0600 Subject: [PATCH] grpc: sandbox: add container when is fully created. Add container to sandbox list until it is created. This commit makes sure to add the container to the sandbox until it is created. This helps to avoid other go routines uses the container structure with nil pointers (because is not fully created). Fixes: #417 Signed-off-by: Jose Carlos Venegas Munoz --- grpc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grpc.go b/grpc.go index 9331151ed4..12c005a8a7 100644 --- a/grpc.go +++ b/grpc.go @@ -560,6 +560,8 @@ func (a *agentGRPC) finishCreateContainer(ctr *container, req *pb.CreateContaine return emptyResp, err } + // Make sure add Container to Sandbox, before call updateSharedPidNs + a.sandbox.setContainer(req.ContainerId, ctr) if err := a.updateSharedPidNs(ctr); err != nil { return emptyResp, err } @@ -606,8 +608,6 @@ func (a *agentGRPC) CreateContainer(ctx context.Context, req *pb.CreateContainer useSandboxPidNs: req.SandboxPidns, } - a.sandbox.setContainer(req.ContainerId, ctr) - // In case the container creation failed, make sure we cleanup // properly by rolling back the actions previously performed. defer func() {