Repository navigation
Description
Summary
core::Error::operator==(const boost::system::error_code&) (and the Error == Error overload) compares the numeric code together with the error category name (src/cpp/shared_core/Error.cpp). Boost's own error_code == errc comparison uses semantic equivalence across categories; ours does not. An Error therefore only matches a code that was built in the same category it was built from, and the codebase has two ways of building an errc-valued Error that land in different categories:
systemError(boost::system::errc::X, location)-> theintoverload ->boost::system::system_category()(name"system").Error(boost::system::errc::X, location)-> impliciterrc -> error_codeconversion ->boost::system::generic_category()(name"generic").
Every existing classification check compares against the system-category form (e.g. error == systemError(boost::system::errc::no_such_file_or_directory, ErrorLocation()), FileLock::isNoLockAvailable, http::isConnectionUnavailableError, the source database supervisor's isLockingUnsupported), so an Error built with the generic form is invisible to all of them.
This bit for real in #18941 / #18944: startHttpConnectionListenerWithTimeout compared the listener's bind error against error_code(errc::address_in_use, generic_category()), while asio reports bind failures in the system category, so the "retry on address in use" loop it guarded had never run. That instance is fixed in #18944; this issue is for what is left.
Latent instances
-
Generic-category constructions.
src/cpp/core/StringUtils.cpp:687and roughly twenty sites insrc/cpp/core/Database.cppbuild errors withError(boost::system::errc::X, ...)(invalid_argument,not_connected,operation_not_supported,resource_unavailable_try_again). Nothing compares against those codes today, so there is no observed misbehavior, but any futureerror == systemError(errc::X, ...)check against them fails silently -- exactly the failure mode duplicate session launch locks the user out: the aborting duplicate removes the live session's socket #18941 had. -
AsyncConnectionImpl::handleStreamError(src/cpp/core/include/core/http/AsyncConnectionImpl.hpp) converts anErrorback intoerror_code(error.getCode(), generic_category())-- the comment there already says the category is wrong.FixedBufferProxy::handleErrorImplre-wraps that code into anErrorand runs it throughisConnectionTerminatedError, whose comparisons are against asio-category codes, so that classification can never match. TodayStreamWriter::handleErrorfilters the connection-terminated cases out before the conversion, so the visible effect is limited to a stream-write failure being logged a second time under the wrong category name. It is one refactor away from misclassifying client disconnects as errors. -
(Related, Windows-only, lower priority.) Several sites compare against errno-valued codes on all platforms --
src/cpp/core/r_util/RToolsInfo.cpp:403,src/cpp/core/http/Util.cpp:701, and thegetCode()checks insrc/cpp/session/modules/SessionChat.cpp-- while the producers report Win32 codes there.ERROR_FILE_NOT_FOUNDhappens to equalENOENT(2), so file-not-found matches by coincidence;ERROR_PATH_NOT_FOUND(3) andERROR_ACCESS_DENIED(5, vsEACCES13) never match. The effect is a less specific message or an extra logged error.shared_core/FilePath.cpp'sisFileNotFoundError/isPathNotFoundError/isNotFoundErroralready handle this correctly and are the pattern to copy.
Possible fixes
- Make
Error::operator==(const boost::system::error_code&)(and ideallyError == Error) use boost's equivalence rules instead of comparing category names, e.g. by resolving the stored category name back to a category for the categories we use (system,generic,asio.misc,asio.ssl, the RStudio custom categories) and comparing througherror_condition. That makes category drift stop mattering everywhere at once, and letshandleStreamErrorhand a correctly categorized code back to its handler. - Or, more narrowly: remove the
Error(boost::system::errc::X, ...)spelling in favor ofsystemError(...), add aboost::system::error_code toErrorCode(const Error&)helper forhandleStreamError, and add a unit test inshared_corethat pins the expected equality semantics so the next drift is caught.
Either way, add a test that Error(errc::X, loc) == systemError(errc::X, loc), which is the property everything in the codebase implicitly assumes.
Activity
fix socket tests on linux, keep the claimed socket from children, rel…
kevinushey commentedon Sep 26, 2026
Update: #18944 no longer changes the
startHttpConnectionListenerWithTimeoutcomparison, so that instance is open again and belongs here. Server sessions no longer reach that loop for a socket in use (they exit at the early claim), but TCP sessions (desktop, and standalone/launcher sessions reusing a port) still do.When fixing it: each retry calls
initializeHttpConnectionListener(), which allocates a new listener without freeing the previous one, so once the comparison matches, every retry leaks a listener along with its io_context and socket. Free or reuse the listener in the same change.don't let a duplicate session launch take over a live session's socket (
compare error codes as conditions and keep stream write errors whole
keep the error guard on socket lookups and fix the lint advice
log the tcp listener's security warnings once across retries
let a user not yet in passwd through the local stream proxy
fail closed on any user lookup failure in the local stream proxy
compare error codes as errc conditions, not raw values
kevinushey commentedon Nov 20, 2026
#19753 covers part of this:
systemError(errc::X)now builds a generic-category error, the same asError(errc::X), andErrorTestspins that the two compare equal.getCode()/value() == errc::Xchecks, including the ones inSessionChat.cpp, now use the newError::matches(errc::X), or Boost'sec == errc::Xfor a rawerror_code. TheRToolsInfo.cppandhttp/Util.cppsites had already been fixed.Still open here:
AsyncConnectionImpl::handleStreamError()still rebuilds the stream write's error aserror_code(error.getCode(), generic_category()).SessionMain.cpp, butstartHttpConnectionListenerWithTimeout()inSessionHttpMethods.cppstill compares the bind error againsterror_code(errc::address_in_use, generic_category()), so its retry still never runs. Enabling it (e.g. witherror.matches(errc::address_in_use)) needed two follow-on fixes in fix errno values read as system error codes #19749: dispose of the listener that failed to bind before creating the next one, and log the TCP listener's startup warnings once rather than on every attempt.pick error categories from the code's type (#19753)