-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(credentials): write an env value and its credential row together #7160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a5bc43
fix(credentials): write an env value and its credential row together
waleedlatif1 a62dd79
fix(workflows): say when a block is dropped before persistence
waleedlatif1 29db915
improvement(chat): stop loading a transcript the v2 route never reads
waleedlatif1 5c4dbed
fix(credentials): serialize every personal env map writer
waleedlatif1 d7b1874
fix(credentials): chunk the credential-ACL write the env save now dep…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { sql } from 'drizzle-orm' | ||
| import type { DbOrTx } from '@/lib/db/types' | ||
|
|
||
| const ENV_MAP_LOCK_TIMEOUT_MS = 5_000 | ||
|
|
||
| /** | ||
| * Serializes every writer of one environment variables map. | ||
| * | ||
| * Both maps are a single jsonb column that every writer read-modify-writes, so | ||
| * without this two concurrent writers each persist their own copy of the map | ||
| * and the later commit silently drops the earlier one's key. The lock is | ||
| * transaction-scoped, so it releases on commit or rollback with no unlock path | ||
| * to miss, and it must be taken before the read that the write is derived from. | ||
| * | ||
| * The keys are the bare workspace or user id, matching every writer that | ||
| * already takes this lock — a prefixed key would be a different lock and would | ||
| * serialize against nothing. | ||
| */ | ||
| async function lockEnvMap(tx: DbOrTx, lockKey: string): Promise<void> { | ||
| await tx.execute(sql`SELECT set_config('lock_timeout', ${`${ENV_MAP_LOCK_TIMEOUT_MS}ms`}, true)`) | ||
| await tx.execute(sql`SELECT pg_advisory_xact_lock(hashtextextended(${lockKey}, 0))`) | ||
| } | ||
|
|
||
| /** Serializes writers of one workspace's environment variables map. */ | ||
| export async function lockWorkspaceEnvMap(tx: DbOrTx, workspaceId: string): Promise<void> { | ||
| await lockEnvMap(tx, workspaceId) | ||
| } | ||
|
|
||
| /** Serializes writers of one user's personal environment variables map. */ | ||
| export async function lockPersonalEnvMap(tx: DbOrTx, userId: string): Promise<void> { | ||
| await lockEnvMap(tx, userId) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.