Skip to content

[v1][breaking] Compiler.Compile and Loader.GetReader should accept a context #89

@robbyt

Description

@robbyt

Summary

The two core interfaces don't accept a context.Context:

  • platform/script/compiler.go:17-29Compile(scriptReader io.ReadCloser)
  • platform/script/loader/loader.go:9-12GetReader() (io.ReadCloser, error)

This causes three concrete problems today:

  1. The Extism compiler stores ctx on the struct via a WithContext option (engines/extism/compiler/compiler.go:17, engines/extism/compiler/options.go:96-104), which is racy if a Compiler is shared across goroutines.

  2. The Risor inner compile hard-codes context.Background() (engines/risor/compiler/internal/compile/compile.go:21), so caller cancellation is ignored entirely.

  3. HTTP compile can hang indefinitely because ExecutableUnit calls GetReader() (platform/script/executableUnit.go:61), not GetReaderWithContext. The HTTP loader has the context-aware variant but nothing reaches for it.

Proposal

  • Compile(ctx context.Context, r io.ReadCloser) (ExecutableContent, error)
  • GetReader(ctx context.Context) (io.ReadCloser, error) — drop the GetReaderWithContext helper as redundant.
  • Delete WithContext from the Extism compiler.
  • Plumb the context through NewExecutableUnit so the loader call gets the same one.

Files

  • platform/script/compiler.go
  • platform/script/loader/loader.go
  • platform/script/loader/{fromHTTP,fromBytes,fromString,fromIoReader,fromDisk}.go
  • platform/script/executableUnit.go
  • engines/{extism,risor,starlark}/compiler/compiler.go
  • engines/risor/compiler/internal/compile/compile.go
  • engines/extism/compiler/options.go (remove WithContext)

This is a breaking-change candidate for v1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions