Skip to content

Allow cancelling tasks that generate SBOM with syft.CreateSBOM() #3705

@danielpacak

Description

@danielpacak

What would you like to be added:

It seems that syft.CreateSBOM(context.Context, source.Source, *CreateSBOMConfig) accepts the Go context as the first argument, but when I pass a cancellable context it's ignored and cataloguers' tasks continue running nevertheless.

ctx := context.Background()
scanCtx, cancelScan := context.WithCancelCause(ctx)
defer cancelScan(nil)

go func() {
	// periodically check for memory pressure against soft memory limit ...

	// if memory is above the watermark
	cancelScan(memory.ErrMemoryPressure)
}()

syftJson, err := syft.CreateSBOM(scanCtx, ...)

Why is this needed:

I'm facing some high memory usage issues with Syft running in a container as a Kubernetes Pod. To bound somehow the upper memory limit before I get OOMKill errors I just want to cancel SBOM generation in idiomatic Go way, i.e. by cancelling the context passed to Syft library method.

Additional context:

  • It seems that the cancellation request is respected by functions that pull down sources from remote registry, but once cataloguer tasks start I cannot stop Syft from running anymore.
  • https://go.dev/doc/database/cancel-operations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions