Skip to content

Fix: don't create .Random.seed as side effect of loading shiny#4383

Merged
gadenbuie merged 1 commit into
mainfrom
fix/4382-loading-random-seed
May 18, 2026
Merged

Fix: don't create .Random.seed as side effect of loading shiny#4383
gadenbuie merged 1 commit into
mainfrom
fix/4382-loading-random-seed

Conversation

@gadenbuie

@gadenbuie gadenbuie commented May 15, 2026

Copy link
Copy Markdown
Member

Fixes #4382

Summary

Loading shiny in a fresh R session (where .Random.seed doesn't yet exist) caused .Random.seed to be created as a side effect. This happened because withPrivateSeed() unconditionally called httpuv::getRNGState() on exit, which calls R's C-level GetRNGstate() — and that function initializes the RNG (creating .Random.seed) when it doesn't already exist.

The fix moves the httpuv::getRNGState() call inside the branch that restores a pre-existing seed. When there was no .Random.seed before the call, we simply remove it and skip the sync — leaving the RNG in the same "not yet initialized" state it was in before package load.

Test plan

  • Existing test-utils.R tests pass (seed save/restore behavior unchanged)
  • Manually verify in a fresh R session:
    exists(".Random.seed", envir = globalenv(), inherits = FALSE)
    #> FALSE
    loadNamespace("shiny")
    exists(".Random.seed", envir = globalenv(), inherits = FALSE)
    #> FALSE

Only call `httpuv::getRNGState()` when restoring a pre-existing
`.Random.seed`, avoiding RNG state creation when none existed before.

Fixes #4382
@gadenbuie gadenbuie changed the title Fix: don't create .Random.seed as side effect of loading shiny Fix: don't create .Random.seed as side effect of loading shiny May 15, 2026
@gadenbuie gadenbuie requested a review from cpsievert May 15, 2026 21:15
@gadenbuie gadenbuie merged commit 22de425 into main May 18, 2026
12 checks passed
@gadenbuie gadenbuie deleted the fix/4382-loading-random-seed branch May 18, 2026 14:35
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.

Loading 'shiny' adds .Random.seed, if non-existing

2 participants