r-lib / processx

Execute and Control Subprocesses from R
https://processx.r-lib.org/
Other
234 stars 43 forks source link

get_id() subtly alters the session randomization state #386

Closed MichaelChirico closed 7 months ago

MichaelChirico commented 7 months ago

https://github.com/r-lib/processx/blob/95ba3aa23262e33b95a1b43dfea822c36589eda3/R/utils.R#L198

Started way upstream as https://github.com/r-lib/pkgload/issues/272 and then https://github.com/r-lib/pkgbuild/issues/185, but the issue traces back to the above -- while trying to build a package, {processx} generates this random ID which messes with the randomization state of the session.

I don't see this documented as intended behavior, so I'm wondering if this is unintentional & perhaps get_id() should be careful to restore the randomization state on completion; of course this means consecutive runs of {processx} may generate sessions with the same ID --> not desirable, so maybe the caller needs to deal with this & {processx} just needs to document the issue?

Alternatively, maybe get_id() could use the tempfile() randomization to generate the IDs, since tempfile() does not touch the R-level randomization state?