Repository navigation
Description
Summary
AsyncClient copies boost::function callbacks out of socketMutex_ before invoking them. Several callback snapshot sites use LOCK_MUTEX / END_LOCK_MUTEX, whose unexpected-exception path logs the exception and continues execution.
If a callback copy throws, execution can therefore continue with only some local state initialized. In deliverChunks(), for example, handlersDisabled_ is copied before fixedBufferHandler_. If the handler copy fails, the local handler remains empty and the decoded chunk is appended to response_ as though no streaming handler were installed. The streaming consumer can then complete without receiving that piece. Similar snapshot behavior in closeAndRespond() and handleWrite() can lose completion or connection notifications.
The realistic trigger is allocation failure while copying boost::function, so this is a very low-probability exception-safety issue rather than a normal operational failure.
Suggested change
Use an explicit lock guard for fallible callback snapshots and handle copy failure as an error. The operation should close or disable the client and take an error path, rather than treating the failed copy as an absent callback. A small helper returning ready, disabled, or failed could keep the behavior consistent across invocation sites.
A fault-injection test using a callable with a throwing copy constructor would help cover this path.
Context
Follow-up from #18541.
Relevant code:
rstudio/src/cpp/core/include/core/http/AsyncClient.hpp
Lines 1460 to 1467 in 2bed86b
| FixedBufferHandler handler; | |
| bool disabled; | |
| LOCK_MUTEX(socketMutex_) | |
| { | |
| disabled = handlersDisabled_; | |
| handler = fixedBufferHandler_; | |
| } | |
| END_LOCK_MUTEX |
Activity
install AsyncClient handlers with copy-then-swap
handle failed handler copies in AsyncClient safely (#18653)