I'm using RMarkdown to generate a large set of individual reports with API calls to get the JSON data for each Rmd report. This code works perfectly fine for a small number of reports. But during larger batch sessions, it will eventually hang, requiring R to be restarted.
person <- req_perform( request(getPersonURL) |> req_headers("Accept" = "application/json") |> req_body_json(list(token = authToken, id = personID)) ) |> resp_body_json()
Eventually, after 100+ requests, it eventually just...stops. No error in console or other output, it simply hangs.
Looking at the logs, it is generating this error:
2023-03-02T22:07:52.950085Z [rsession-username] ERROR asio.misc error 4 (The descriptor does not fit into the select call's fd_set);
OCCURRED AT void rstudio::session::HttpConnectionImpl<rstudio_boost::asio::ip::tcp>::handleRead(const boost::system::error_code &, std::size_t) [ProtocolType = rstudio_boost::asio::ip::tcp] src/cpp/session/http/SessionPosixHttpConnectionListener.cpp:370;
LOGGED FROM: void rstudio::session::HttpConnectionImpl<rstudio_boost::asio::ip::tcp>::handleRead(const boost::system::error_code &, std::size_t) [ProtocolType = rstudio_boost::asio::ip::tcp] src/cpp/session/http/SessionPosixHttpConnectionListener.cpp:372
This behavior is consistent, and repeated on my M1 Mac (MacOS 12.6.3) and Intel Mac (MacOS 12.6.3), with both R4.2.2 and R4.1.2. Packages up to date and RStudio is 2022.12.0+353. I get this error using both
There are no errors on the server side of things, and everything works if I just do small batches. It's just when I try to run a large batch of persons (100+) that it will eventually throw the above error. Sometimes after 100 reports, sometimes after 300 reports. It is not consistent, but has always failed eventually.
Running the script from
RScript at the command line also fails, but it spits out an HTTP 500 error message and aborts instead of hanging. Checking the server confirms no errors server side.