Skip to content

fix: wrap std::env::set_var in unsafe block for Rust 2024 edition#256

Merged
pinodeca merged 1 commit into
microsoft:mainfrom
iemejia:fix/unsafe-set-var
Jun 18, 2026
Merged

fix: wrap std::env::set_var in unsafe block for Rust 2024 edition#256
pinodeca merged 1 commit into
microsoft:mainfrom
iemejia:fix/unsafe-set-var

Conversation

@iemejia

@iemejia iemejia commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Split from #221 to ease review.

std::env::set_var becomes unsafe in the Rust 2024 edition because it can cause undefined behavior when other threads read the environment concurrently.

Add SAFETY documentation explaining why set_var is acceptable here: PostgreSQL backends are forked single-process, and the BGW tokio runtime uses new_current_thread() with no additional OS threads spawned.

Files: src/worker.rs, src/client.rs
Tests: Purely mechanical annotation — zero behavioral change.

@pinodeca pinodeca 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.

LGTM!

std::env::set_var becomes unsafe in the Rust 2024 edition because it can
cause undefined behavior when other threads are reading the environment
concurrently.

Add SAFETY documentation explaining why set_var is acceptable here:
PostgreSQL backends are forked single-process, and the BGW tokio runtime
uses new_current_thread() with no additional OS threads spawned.
@iemejia iemejia force-pushed the fix/unsafe-set-var branch from f386cf0 to 72e1757 Compare June 18, 2026 20:08

@pinodeca pinodeca 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.

LGTM!

@pinodeca pinodeca merged commit 22e4cf9 into microsoft:main Jun 18, 2026
5 checks passed
@iemejia iemejia deleted the fix/unsafe-set-var branch June 18, 2026 22:38
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