Skip to content

[Golden Wattle] drive ppm vulnerability display off the session repositories, not env vars - #17823

Merged
kevinushey merged 3 commits into
rel-golden-wattlefrom
bugfix/ppm-vulnerability-enablement-golden-wattle
Jun 2, 2026
Merged

kevinushey merged 3 commits into
rel-golden-wattlefrom
bugfix/ppm-vulnerability-enablement-golden-wattle

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Backport of #17822 to rel-golden-wattle.

Fixes a regression introduced by #17808, which is present on this release branch. That PR moved the PPM vulnerability download off the R main thread (addressing the startup delay in #17807), but in the rewrite it reintroduced an isPpmIntegrationEnabled() gate on the vulnerability path -- in both refreshVulnerabilitiesAsync() (C++) and getVulnerabilityRequestPlan() (R).

isPpmIntegrationEnabled() is satisfied only by the Workbench-injected PWB_PPM_* environment variables. So any session that points options(repos) at a Posit Package Manager instance by hand -- without Workbench PPM integration configured -- stopped showing vulnerability badges in the Packages pane entirely.

Vulnerability display is intentionally not opt-in. This was made an explicit decision in 88778df845 ("always try to provide vuln info if available"), which removed an env-var gate that had been applied incidentally when the metadata column landed. The env-var gate is meant only for the Workbench-only metadata column.

Changes

  • SessionPPM.cpp: remove the isPpmIntegrationEnabled() early-return in refreshVulnerabilitiesAsync().
  • SessionPPM.R: remove the isIntegrationEnabled() gate at the top of getVulnerabilityRequestPlan(); enablement is again driven by detecting a PPM URL in getOption("repos") (the per-repo fromRepositoryUrl check already in the loop). A cheap PPM-URL pre-filter is added so installed.packages() is still skipped for non-PPM sessions.
  • Both call sites carry comments recording the motivation (and the 88778df845 reference).
  • test-ppm.R: replace the now-obsolete "returns nothing when integration is disabled" test with a regression guard ("ignores the integration-enabled flag"); drop the now-dead isIntegrationEnabled()=TRUE mocks from the other plan tests.

The metadata column remains gated by isPpmMetadataColumnEnabled() exactly as before.

Testing

Cherry-picked cleanly from #17822; the resulting diff is byte-identical, and the SessionPPM files on this branch match main at the changed locations. Verified on the equivalent main change:

  • cmake --build . --target rsession -- compiles and links cleanly.
  • rstudio-tests --scope r --filter ppm -- [ FAIL 0 | WARN 0 | SKIP 0 | PASS 69 ].
  • rstudio-tests --scope rsession --filter ppm -- 231 passed, 0 failed.

Notes

… vars

Vulnerability badges in the Packages pane are intentionally not opt-in: they
should appear whenever the session is using a Posit Package Manager repository
(a PPM URL in getOption("repos")), including open-source / desktop RStudio. This
was made an explicit decision in 88778df "always try to provide vuln info if
available", which removed an env-var gate that had been applied incidentally.

The async rewrite in #17808 reintroduced that gate, adding isPpmIntegrationEnabled()
early-returns to both refreshVulnerabilitiesAsync() (C++) and
getVulnerabilityRequestPlan() (R). isPpmIntegrationEnabled() requires the
Workbench-injected PWB_PPM_* env vars, so any session that points options(repos)
at PPM by hand (without Workbench PPM integration configured) stopped showing
vulnerability badges entirely.

Remove both gates so enablement is once again driven by repository detection,
keeping the env-var gate only for the Workbench-only metadata column. Add a
cheap PPM-URL pre-filter so installed.packages() is still skipped for non-PPM
sessions, and add comments recording the motivation.
@gtritchie gtritchie added this to the Golden Wattle milestone Jun 2, 2026
- guard .rs.ppm.fromRepositoryUrl against non-string/NA repo entries so an
  NA in getOption("repos") no longer aborts the now-unconditional vuln plan
- soften the integration-gate comment (the env-var gate also feeds
  ppm_integration_enabled in client session info)
- add tests: mixed PPM/non-PPM repos, installed.packages() skip for non-PPM
  sessions, NA repo tolerance, and direct fromRepositoryUrl coverage

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kevinushey
kevinushey merged commit d236acd into rel-golden-wattle Jun 2, 2026
1 check was pending
@kevinushey
kevinushey deleted the bugfix/ppm-vulnerability-enablement-golden-wattle branch June 2, 2026 23:15
kevinushey added a commit that referenced this pull request Jun 18, 2026
On project switch/close, the desktop session quits via exitEarly() ->
::exit(), which runs static/global destructors. The server_rpc file-scope
io_context worker thread was launched detached and never stopped, so
~io_context() could run on the main thread while the worker was still
inside run() -- undefined behavior that hangs on Windows (IOCP). This
began affecting ordinary desktop users once the PPM vulnerability fetch
(#17808) started driving async work on that io_context for any session
using a Posit Package Manager repository (#17823).

Retain a joinable handle for the server_rpc worker and stop+join it from
exitEarly(), via a new core::thread::joinOrAbandonThread() helper that
bounds the wait (timed_join) and detaches on timeout, so the exit path can
never trade the teardown hang for an indefinite join hang. The helper
never throws (safe to call from a destructor) and requires callers to
state whether the thread needs interrupting, since io_context workers are
not interruption points and must be released via io_context::stop().

The monitor io_context worker had the same latent race (stopped but never
joined); fix it the same way. Migrate the other duplicated join/log/detach
shutdown tails (OfflineService, ClientEventService, file monitor,
ConsoleInputService, HttpConnectionListener) onto the shared helper; this
also fixes a latent std::terminate in ConsoleInputService's destructor,
which left its thread joinable on a join timeout.

Addresses #18018.
kevinushey added a commit that referenced this pull request Jun 18, 2026
…18021)

* fix windows hang on project switch from unstopped io_context workers

On project switch/close, the desktop session quits via exitEarly() ->
::exit(), which runs static/global destructors. The server_rpc file-scope
io_context worker thread was launched detached and never stopped, so
~io_context() could run on the main thread while the worker was still
inside run() -- undefined behavior that hangs on Windows (IOCP). This
began affecting ordinary desktop users once the PPM vulnerability fetch
(#17808) started driving async work on that io_context for any session
using a Posit Package Manager repository (#17823).

Retain a joinable handle for the server_rpc worker and stop+join it from
exitEarly(), via a new core::thread::joinOrAbandonThread() helper that
bounds the wait (timed_join) and detaches on timeout, so the exit path can
never trade the teardown hang for an indefinite join hang. The helper
never throws (safe to call from a destructor) and requires callers to
state whether the thread needs interrupting, since io_context workers are
not interruption points and must be released via io_context::stop().

The monitor io_context worker had the same latent race (stopped but never
joined); fix it the same way. Migrate the other duplicated join/log/detach
shutdown tails (OfflineService, ClientEventService, file monitor,
ConsoleInputService, HttpConnectionListener) onto the shared helper; this
also fixes a latent std::terminate in ConsoleInputService's destructor,
which left its thread joinable on a join timeout.

Addresses #18018.

* detect ppm repository urls with a trailing slash

.rs.ppm.fromRepositoryUrl matched with a fully-anchored regex ending in
(?<snapshot>[^/]+)$, so a repo URL with a trailing slash (e.g.
".../cran/latest/") did not match and yielded an empty vulnerability
request plan. RStudio's own CRAN-mirror UI normalizes repo URLs with a
trailing slash, so users who configured a PPM repo that way silently got
no vulnerability badges. Tolerate an optional trailing slash in the
detection regex.

Addresses #18018.

* migrate server child-reaper join onto joinOrAbandonThread

ServerMain's shutdown child-reaper thread used a bare timed_join(60s); on
timeout the thread stayed joinable and ~boost::thread would std::terminate.
Route it through core::thread::joinOrAbandonThread so a child that refuses
to die is abandoned (and the existing stuck-process check reports it)
rather than crashing shutdown. The reaper blocks in waitpid(), not an
interruption point, so interrupt is false.

(Win32ChildProcess's pipe-reader timed_joins are intentionally left as-is:
one reader writes an outer stack buffer by reference, so detaching it on
timeout would be a use-after-scope -- it needs a different fix, not this
mechanical migration.)

Addresses #18018.

* leak io_context globals so abandoned-worker exit can't run ~io_context()

* address pr review: unit-test joinOrAbandonThread and minor doc/test fixes
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