Skip to content

R code run from the idle event loop (e.g. shiny::runApp() via later::later()) makes the session unresponsive and uninterruptible #19236

Closed

Description

@kevinushey

System details

RStudio Edition : Desktop and Server
RStudio Version : main (2026.12 daily), also reproduced on 2026.09
OS Version      : macOS 27, Ubuntu 24.04
R Version       : 4.6.1

Steps to reproduce the problem

In the Console, schedule a blocking loop on R's event loop rather than running it as console input:

later::later(function() shiny::runApp(shiny::shinyApp(shiny::fluidPage("hi"), function(input, output) NULL)), 1)

Then try to do anything that needs the session: run another command, change a preference, click the Viewer's stop button, press Esc / the interrupt button, or reload the browser.

Describe the problem in detail

Once the callback starts, the IDE is deaf. The app runs (the Viewer shows it, console output arrives), but every request that must be handled by the session's main thread sits in the connection queue until the callback returns, which for runApp() is never:

  • console input is echoed but never executes
  • preference writes and every other RPC hang (the client's async-RPC acknowledgement arrives, the result never does)
  • the Viewer stop button and the interrupt command do nothing: the interrupt RPC is itself queued, and even when handled it is dropped because interrupts are only armed while console input is executing
  • a browser reload never gets past client_init
  • there is no busy indicator, so nothing suggests R is busy and the "R is not responding" / Terminate dialog never engages

The only recovery is killing rsession.

A stack sample of the wedged main thread:

rConsoleRead -> http_methods::waitForMethod -> processEvents -> R_runHandlers
  -> later async_input_handler -> execCallbacksForTopLevel -> <callback>
  -> shiny::runApp -> later execCallbacks -> CallbackRegistry::wait

Why: while R is idle at the prompt, waitForMethod() is what dequeues requests, and it only does so between calls to processEvents() (which runs R's input handlers, including later's). If an input handler runs a long-lived callback, waitForMethod() never gets control back. The other drain, polledEventHandler() in SessionHttpMethods.cpp, only serves queued requests while console_input::executing() is true, and that flag is false here because, as far as the console is concerned, R is sitting at the prompt. The interrupt handler is gated on the same flag.

This is the same class as #17178 (help "Run examples" running runApp() on the event loop), which #17908 worked around for that one entry point. Any code path that schedules a blocking loop through later hits it: later::later(runApp), plumber/httpuv servers started from a callback, async packages whose callbacks block. It also took out a CI shard in #19226 when the Posit Assistant chose this launch style "to keep the console free".

Describe the behavior you expected

R code run from the idle event loop should be treated like any other busy R: the session keeps serving requests, interrupts stop it, and after a moment the console shows that R is busy.

Activity

  1. self-assigned this
    on Oct 23, 2026
  2. added theissue type on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions