summaryrefslogtreecommitdiff
path: root/include/obmc_console.hpp
diff options
context:
space:
mode:
authorAppaRao Puli <apparao.puli@linux.intel.com>2020-11-17 08:33:11 +0300
committerAppaRao Puli <apparao.puli@linux.intel.com>2020-11-17 08:33:11 +0300
commit5238bd3205c61efa4ff82c0c5a4eb9d594a0865b (patch)
treebfd821d1437095db1cc6f6c3746afb42abb86b29 /include/obmc_console.hpp
parent929d4b57f10bc4200e16b71fbcf32521d8cc23c1 (diff)
downloadbmcweb-5238bd3205c61efa4ff82c0c5a4eb9d594a0865b.tar.xz
fix bmcweb crash during sol communication
After establishing the obmc_console socket communication, If client closes the connection abruptly, async read/write operation fails with asio.ssl.stream error. To handle the error, it calls closeHandler call back function and cleans the session and socket. Any ongoing async read operation should be discarded by checking socket handle. Read/Write the message from stream via async_read_some()/async_write without checking socket handle, causes the crash. Added socket handle validation before performing any read/write operation to avoid crash. Tested: - Without fix, when sol connection closes abruptly, at times saw the crash with below logs. Nov 13 11:32:51 intel-obmc bmcweb[20169]: doRead error asio.ssl.stream:1 Nov 13 11:32:51 intel-obmc systemd[1]: bmcweb.service: Main process exited, code=dumped, status=11/SEGV Nov 13 11:32:51 intel-obmc systemd[1]: bmcweb.service: Failed with result 'core-dump'. - With fix, verified the case and no crashes seen. Nov 13 12:55:04 intel-obmc bmcweb[24426]: (2020-11-13 12:55:04) [ERROR "websocket.h":207] doRead error asio.ssl.stream:1 Nov 13 12:55:04 intel-obmc bmcweb[24426]: (2020-11-13 12:55:04) [ERROR "obmc_console.hpp":67] doread() - Socket closed Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com> Change-Id: I2afda509ca77a561651a8682e042c45ca7366642
Diffstat (limited to 'include/obmc_console.hpp')
-rw-r--r--include/obmc_console.hpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index 645ea8cdf5..17c106fbd5 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -36,6 +36,12 @@ inline void doWrite()
return;
}
+ if (!hostSocket)
+ {
+ BMCWEB_LOG_ERROR << "doWrite(): Socket closed.";
+ return;
+ }
+
doingWrite = true;
hostSocket->async_write_some(
boost::asio::buffer(inputBuffer.data(), inputBuffer.size()),
@@ -62,6 +68,12 @@ inline void doWrite()
inline void doRead()
{
+ if (!hostSocket)
+ {
+ BMCWEB_LOG_ERROR << "doRead(): Socket closed.";
+ return;
+ }
+
BMCWEB_LOG_DEBUG << "Reading from socket";
hostSocket->async_read_some(
boost::asio::buffer(outputBuffer.data(), outputBuffer.size()),
@@ -125,6 +137,8 @@ inline void requestRoutes(App& app)
})
.onclose([](crow::websocket::Connection& conn,
[[maybe_unused]] const std::string& reason) {
+ BMCWEB_LOG_INFO << "Closing websocket. Reason: " << reason;
+
sessions.erase(&conn);
if (sessions.empty())
{