SOL: Fix coredump due to recursive call deadlock
When the data buffer size is always larger than the send threshold.
The recursive call deadlock when any input event is received.
the backtrace is as below:
- enableAccumulateTimer
- charAccTimerHandler
- sendOutboundPayload
- enableAccumulateTimer
using io.post avoid the recursive call deadlock.
Change-Id: Ic67d2c6dfce5c658b7ef4813bf3a62ad93ced8ad
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
diff --git a/sol/sol_context.cpp b/sol/sol_context.cpp
index 7bae1cb..2dbdf60 100644
--- a/sol/sol_context.cpp
+++ b/sol/sol_context.cpp
@@ -44,13 +44,19 @@
if (enable)
{
auto bufferSize = sol::Manager::get().dataBuffer.size();
+ std::weak_ptr<Context> weakRef = weak_from_this();
if (bufferSize > sendThreshold)
{
- charAccTimerHandler();
+ getIo()->post([weakRef]() {
+ std::shared_ptr<Context> self = weakRef.lock();
+ if (self)
+ {
+ self->charAccTimerHandler();
+ }
+ });
return;
}
accumulateTimer.expires_after(interval);
- std::weak_ptr<Context> weakRef = weak_from_this();
accumulateTimer.async_wait(
[weakRef](const boost::system::error_code& ec) {
std::shared_ptr<Context> self = weakRef.lock();