Skip to content

fix: prevent dev mode bundle deletion race condition#6419

Open
JoshuaShunk wants to merge 1 commit intoanomalyco:devfrom
JoshuaShunk:fix/dev-bundle-race-condition
Open

fix: prevent dev mode bundle deletion race condition#6419
JoshuaShunk wants to merge 1 commit intoanomalyco:devfrom
JoshuaShunk:fix/dev-bundle-race-condition

Conversation

@JoshuaShunk
Copy link
Copy Markdown

Summary

Fixes #6416

In sst dev, Build() calls os.RemoveAll on the artifacts directory before every rebuild. In dev mode, esbuild maintains a persistent context and overwrites output files in place via Rebuild(), so the full directory wipe is unnecessary. When multiple Lambda bridge instances connect for the same function (common with CloudFront/Router), this creates a race condition where running workers lose their bundle.mjs mid-flight.

Changes:

  • Skip os.RemoveAll on the artifacts output directory during dev mode rebuilds
  • Validate cached build output in getBuildOutput() by checking the handler file still exists on disk before returning a cache hit — if missing, invalidate the cache and trigger a rebuild

Test plan

  • go vet ./... passes
  • go test ./pkg/... passes
  • go build ./cmd/sst succeeds

Comment on lines +192 to +208
// check that the handler file still exists on disk
handlerFile := build.Handler
if i := strings.LastIndex(handlerFile, "."); i > 0 {
handlerFile = handlerFile[:i]
}
matches, _ := filepath.Glob(filepath.Join(build.Out, handlerFile+".*"))
if len(matches) == 0 {
// also check without extension for compiled binaries
if _, err := os.Stat(filepath.Join(build.Out, handlerFile)); err != nil {
log.Info("build output missing, rebuilding", "functionID", functionID, "handler", build.Handler)
delete(builds, functionID)
} else {
return build
}
} else {
return build
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thansk for your contribution @JoshuaShunk

i'm thinking maybe we don't need this complex logic given the fix in runtime.go should prevent this altogether

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SST Dev Mode Worker Reboot Bug - Bundle Deletion Race Condition

2 participants