Skip to content

Commit

Permalink
Fix index info command with containerd content store
Browse files Browse the repository at this point in the history
Previously SOCI CLI index info command would fail with context deadline
exceeded error when the content store was set to containerd. The root
cause was the default global duration for the app context is zero if not
set. The result was Go context with an immediate deadline thus resulting
in the error. The fix is to not set a deadline if the duration is zero.

Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez committed Dec 8, 2023
1 parent cf25e82 commit 78d77d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 4 additions & 3 deletions cmd/soci/commands/index/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package index

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"os"

"github.com/awslabs/soci-snapshotter/cmd/soci/commands/internal"
"github.com/awslabs/soci-snapshotter/soci"
"github.com/awslabs/soci-snapshotter/soci/store"

Expand All @@ -38,6 +38,9 @@ var infoCommand = cli.Command{
Description: "get detailed info about an index",
ArgsUsage: "<digest>",
Action: func(cliContext *cli.Context) error {
ctx, cancel := internal.AppContext(cliContext)
defer cancel()

digest, err := digest.Parse(cliContext.Args().First())
if err != nil {
return err
Expand All @@ -53,8 +56,6 @@ var infoCommand = cli.Command{
if artifactType == soci.ArtifactEntryTypeLayer {
return fmt.Errorf("the provided digest is of ztoc not SOCI index. Use \"soci ztoc info\" command to get detailed info of ztoc")
}
ctx, cancel := context.WithTimeout(context.Background(), cliContext.GlobalDuration("timeout"))
defer cancel()
ctx, store, err := store.NewContentStore(ctx, store.WithType(store.ContentStoreType(cliContext.GlobalString("content-store"))), store.WithNamespace(cliContext.GlobalString("namespace")))
if err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/soci/commands/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc)

// NewClient returns a new containerd client
func NewClient(context *cli.Context, opts ...containerd.ClientOpt) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) {
timeoutOpt := containerd.WithTimeout(context.GlobalDuration("connect-timeout"))
opts = append(opts, timeoutOpt)
opts = append(opts, containerd.WithTimeout(context.GlobalDuration("timeout")))
address := strings.TrimPrefix(context.GlobalString("address"), "unix://")
client, err := containerd.New(address, opts...)
if err != nil {
Expand Down

0 comments on commit 78d77d6

Please sign in to comment.