Skip to content

Conversation

@jumski
Copy link
Contributor

@jumski jumski commented Dec 1, 2025

Add Advisory Locks to Prevent Concurrent Flow Compilation Race Conditions

This PR adds transaction-level advisory locks to the ensure_flow_compiled function to prevent race conditions during concurrent flow compilation attempts. The implementation:

  • Generates a deterministic lock key from the flow slug using hashtext()
  • Acquires a transaction-level advisory lock with pg_advisory_xact_lock(1, v_lock_key)
  • Ensures that concurrent compilation attempts for the same flow are properly serialized

A comprehensive stress test was added that verifies the locking behavior by:

  • Creating 50 separate database connections
  • Attempting to compile the same flow simultaneously
  • Verifying that exactly one compilation succeeds while the others verify the existing flow
  • Confirming that only one flow and one step exist in the database after all operations

This change prevents potential data corruption or duplicate entries that could occur when multiple workers attempt to compile the same flow simultaneously.

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

⚠️ No Changeset found

Latest commit: bcc4f76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor Author

jumski commented Dec 1, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge:queue - adds this PR to the back of the merge queue
  • hotfix:queue - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@nx-cloud
Copy link

nx-cloud bot commented Dec 1, 2025

View your CI Pipeline Execution ↗ for commit bcc4f76

Command Status Duration Result
nx run cli:e2e ✅ Succeeded 3s View ↗
nx run core:pgtap ✅ Succeeded 24s View ↗
nx run client:e2e ✅ Succeeded 1m 9s View ↗
nx affected -t verify-exports --base=origin/mai... ✅ Succeeded 3s View ↗
nx affected -t build --configuration=production... ✅ Succeeded 25s View ↗
nx affected -t lint typecheck test --parallel -... ✅ Succeeded 41s View ↗
nx run edge-worker:test:integration ✅ Succeeded 4m 48s View ↗
nx run edge-worker:e2e ✅ Succeeded 36s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-03 18:59:58 UTC

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2025

🔍 Preview Deployment: Website

Deployment successful!

🔗 Preview URL: https://pr-477.pgflow.pages.dev

📝 Details:

  • Branch: 12-01-add_advisory_lock_to_ensure_flow_compiled_to_prevent_race_conditions
  • Commit: b826d428e4da2b22d40db23e2407832d5cfba8c7
  • View Logs

_Last updated: _

@jumski jumski force-pushed the 12-01-add_advisory_lock_to_ensure_flow_compiled_to_prevent_race_conditions branch from 810954f to bcc4f76 Compare December 3, 2025 18:43
@jumski jumski force-pushed the 12-01-remove_unused_ensure-compiled_http_endpoint_from_controlplane branch from 8875a41 to 58d1ef1 Compare December 3, 2025 18:43
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