Skip to content

Fix: Build clients race condition - #126

Merged
willemneal merged 12 commits into
mainfrom
fix/build-client-race-cond
Jul 8, 2025
Merged

Fix: Build clients race condition#126
willemneal merged 12 commits into
mainfrom
fix/build-client-race-cond

Conversation

@zachfedor

Copy link
Copy Markdown
Contributor

Previously, the client build process deleted the old contract code before building and installing the new ones. While running in watch mode concurrently with the frontend dev server, this caused a hot-reload which would throw an error since app code is importing contracts that don't exist until rebuilt.

This change builds and installs the contracts in a temp directory then replaces the contract code at once, ensuring only one hot-reload and no broken imports. This has the added benefit of being able to use the old contract code as a backup if the build/install process fails for any reason.

Previously, the client build process deleted the old contract code
before building and installing the new ones. While running in watch mode
concurrently with the frontend dev server, this caused a hot-reload
which would throw an error since app code is importing contracts that
don't exist until rebuilt.

This change builds and installs the contracts in a temp directory then
replaces the contract code at once, ensuring only one hot-reload and no
broken imports. This has the added benefit of being able to use the old
contract code as a backup if the build/install process fails for any
reason.

@BlaineHeffron BlaineHeffron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work, I think this a good solution. You shouldn't need to copy the contract template to the temporary directory since that lives in a separate place from the typescript bindings. I would just remove that (and that should remove the need for the write_contract_template_to_dir refactor).

Comment thread crates/stellar-scaffold-cli/src/commands/build/clients.rs
Comment thread crates/stellar-scaffold-cli/src/commands/build/clients.rs Outdated
Comment thread crates/stellar-scaffold-cli/src/commands/build/clients.rs Outdated
@willemneal
willemneal requested a review from BlaineHeffron July 7, 2025 20:19

@BlaineHeffron BlaineHeffron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When I run build clients I get an error: Error: Directory not empty (os error 39)
It appears to be happening during the rename line 357. Might need to supply options to rewrite or use a different fn.

Comment thread crates/stellar-scaffold-cli/src/commands/build/clients.rs Outdated
@BlaineHeffron
BlaineHeffron requested a review from willemneal July 8, 2025 16:58
@willemneal
willemneal enabled auto-merge (squash) July 8, 2025 17:15
@willemneal
willemneal requested a review from BlaineHeffron July 8, 2025 17:15
@willemneal
willemneal merged commit 1bb8c7e into main Jul 8, 2025
1 of 2 checks passed
@BlaineHeffron
BlaineHeffron deleted the fix/build-client-race-cond branch July 8, 2025 17:52
@aha-release-plz aha-release-plz Bot mentioned this pull request Jul 8, 2025
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.

3 participants