Skip to content

fix(aws): use mutex for deployment-etag cache#1996

Merged
lionello merged 1 commit intomainfrom
lio/ecs-cache-lock
Mar 19, 2026
Merged

fix(aws): use mutex for deployment-etag cache#1996
lionello merged 1 commit intomainfrom
lio/ecs-cache-lock

Conversation

@lionello
Copy link
Copy Markdown
Member

@lionello lionello commented Mar 19, 2026

Description

Fix panic when receiving ECS events from different go routines.
Untitled.txt

Linked Issues

Checklist

  • I have performed a self-review of my code
  • I have added appropriate tests
  • I have updated the Defang CLI docs and/or README to reflect my changes, if necessary

Summary by CodeRabbit

Release Notes

  • Refactor

    • Updated internal event handling interfaces for improved type consistency and safety across cloud infrastructure modules.
    • Refactored cache implementation to support concurrent access with thread-safe operations.
  • Chores

    • Enhanced debug logging for error diagnostics in session management.

@lionello lionello requested a review from edwardrf March 19, 2026 18:58
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0257439-970f-485f-8b32-15078af131be

📥 Commits

Reviewing files that changed from the base of the PR and between 22cc444 and c51d2a2.

📒 Files selected for processing (3)
  • src/cmd/cli/command/session.go
  • src/pkg/clouds/aws/codebuild/event.go
  • src/pkg/clouds/aws/ecs/event.go

📝 Walkthrough

Walkthrough

The pull request updates AWS event handling to use typed types.ETag instead of plain strings across CodeBuild and ECS implementations. Additionally, the ECS cache is refactored from a map alias to a mutex-guarded struct for thread-safety. A debug log is added to session initialization for error reporting.

Changes

Cohort / File(s) Summary
Session Initialization Logging
src/cmd/cli/command/session.go
Added debug log emission when loader.ProjectWorkingDir(ctx) fails in newStackManagerForLoader, maintaining existing fallback behavior.
CodeBuild Event Interface
src/pkg/clouds/aws/codebuild/event.go
Updated Event interface and CodebuildEvent implementation to return types.ETag instead of string in Etag() method signature.
ECS Event and Cache Refactoring
src/pkg/clouds/aws/ecs/event.go
Converted Cache interface to use types.ETag, refactored LocalCache from map alias to struct with sync.RWMutex for thread-safety, updated DeploymentEtags initialization, and changed all event types' Etag() signatures to return types.ETag.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • jordanstephens
  • edwardrf

Poem

🐰 Types now bloom with clarity bright,
ETag's no string, but typed just right!
Cache gains mutex, threads won't clash,
Etags flow swift through AWS bash!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding mutex protection to the deployment-etag cache in AWS ECS code, which aligns with the primary modification of converting LocalCache to a mutex-guarded struct.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lio/ecs-cache-lock
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

level=warning msg="[linters_context] running gomodguard failed: unable to read module file go.mod: current working directory must have a go.mod file: if you are not using go modules it is suggested to disable this linter"
level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands and usage tips.

@lionello lionello merged commit 70fb304 into main Mar 19, 2026
14 checks passed
@lionello lionello deleted the lio/ecs-cache-lock branch March 19, 2026 19:57
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.

2 participants