-
Notifications
You must be signed in to change notification settings - Fork 237
Fix race conditions interacting with Cloud SQLite jobs #9207
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 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e728ad1
Fix race conditions interacting with Cloud SQLite jobs
tcobbs-bentley 61d060f
Clear timer immediately if error occurs in timer callback
tcobbs-bentley 42965d6
Add integration test
tcobbs-bentley 0c7349b
rush change
tcobbs-bentley b6aa1f0
Potential fix for pull request finding 'Semicolon insertion'
tcobbs-bentley 6861656
Potential fix for pull request finding 'Semicolon insertion'
tcobbs-bentley 73eec63
Prevent any exceptions from being thrown in setInterval handlers
tcobbs-bentley e3efa28
rush extract-api
tcobbs-bentley de651b8
rush change
tcobbs-bentley 363c049
Fix intervalWrapper and rename to wrapTimerCallback + add unit tests
tcobbs-bentley 7905ac8
Merge branch 'master' into tcobbs/cloudsqlite-job-race-fix
tcobbs-bentley 8cc4846
rush extract-api
tcobbs-bentley 212e2f3
Fix so most pertinent error is thrown
tcobbs-bentley 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
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/core-backend/tcobbs-cloudsqlite-job-race-fix_2026-04-16-20-40.json
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,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@itwin/core-backend", | ||
| "comment": "", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@itwin/core-backend" | ||
| } |
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/core-bentley/tcobbs-cloudsqlite-job-race-fix_2026-04-17-16-25.json
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,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@itwin/core-bentley", | ||
| "comment": "Added intervalWrapper utility function.", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@itwin/core-bentley" | ||
| } |
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,49 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
| * See LICENSE.md in the project root for license terms and full copyright notice. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
| /** @packageDocumentation | ||
| * @module Utils | ||
| */ | ||
|
|
||
| /** | ||
| * Wrapper function designed to be used for callbacks called by setInterval in order to propagate any exceptions | ||
| * thrown in the callback to the main promise chain. It does this by creating a new promise for the callback | ||
| * invocation and adding it to the intervalPromises set. The main promise chain can then await | ||
| * Promise.all(intervalPromises) to catch any exceptions thrown in any of the callbacks. Note that if the callback | ||
| * completes successfully, the promise is resolved and removed from the set. If it throws an exception, the promise is | ||
| * rejected but not removed from the set, so that the main promise chain can detect that an error occurred and handle | ||
| * it appropriately. | ||
| * @param intervalPromises A set of promises representing the currently active interval callbacks. | ||
| * @param callback The async callback to be executed within the interval. | ||
| * @beta | ||
| */ | ||
| export async function intervalWrapper(intervalPromises: Set<Promise<void>>, callback: () => Promise<void>) { | ||
|
ben-polinsky marked this conversation as resolved.
Outdated
|
||
| let resolvePromise: (() => void) | undefined; | ||
| let rejectPromise: ((reason?: any) => void) | undefined; | ||
|
|
||
| // The callback of the Promise constructor does not have access to the promise itself, so all we do there is | ||
| // capture the resolve and reject functions for use in the async code below that would have otherwise been | ||
| // placed in the setInterval callback. | ||
| const intervalPromise = new Promise<void>((resolve, reject) => { | ||
| resolvePromise = resolve; | ||
| rejectPromise = reject; | ||
| }); | ||
| // Note: when we get here, resolvePromise and rejectPromise will always be defined, but there is no way to | ||
| // convince TS of that fact without extra unnecessary checks, so we use ?. when accessing them. | ||
|
|
||
| intervalPromises.add(intervalPromise); | ||
|
|
||
| const cleanupAndResolve = () => { | ||
| resolvePromise?.(); | ||
| // No need to keep track of this promise anymore since it's resolved. | ||
| intervalPromises.delete(intervalPromise); | ||
| }; | ||
|
|
||
| try { | ||
| await callback(); | ||
| cleanupAndResolve(); | ||
| } catch (err) { | ||
| rejectPromise?.(err); | ||
| } | ||
| } | ||
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
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.