Skip to content

Commit e0ccc57

Browse files
trondndaverigby
authored andcommitted
MB-28630: Extend log info for exception in runloop
If an exception is thrown while executing stuff for a connection it is being caught and the connection is being shut down. Log the entire cookie information if the exception occurs during packet execution. For the other states include the state name in the exception. In addition to that catch std::bad_alloc and ignore logging if it is being thrown while adding log entries (to avoid crashing the server) Change-Id: Ib7700e5b7099ccaa054dfd2f61f2784f76399815 Reviewed-on: http://review.couchbase.org/90843 Tested-by: Build Bot <[email protected]> Reviewed-by: Tim Bradgate <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent b3629c9 commit e0ccc57

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

daemon/connection_mcbp.cc

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,37 @@ void McbpConnection::runEventLoop(short which) {
972972
try {
973973
runStateMachinery();
974974
} catch (const std::exception& e) {
975-
LOG_WARNING(
976-
"{}: exception occurred in runloop - closing connection: {}",
977-
getId(),
978-
e.what());
975+
bool logged = false;
976+
if (getState() == McbpStateMachine::State::execute) {
977+
try {
978+
// Converting the cookie to json -> string could probably
979+
// cause too much memory allcation. We don't want that to
980+
// cause us to crash..
981+
LOG_WARNING(
982+
"{}: exception occurred in runloop during packet "
983+
"execution. Cookie info: {} - closing connection: {}",
984+
getId(),
985+
to_string(getCookieObject().toJSON()),
986+
e.what());
987+
logged = true;
988+
} catch (const std::bad_alloc&) {
989+
// none
990+
}
991+
}
992+
993+
if (!logged) {
994+
try {
995+
LOG_WARNING(
996+
"{}: exception occurred in runloop (state: \"{}\") - "
997+
"closing connection: {}",
998+
getId(),
999+
getStateName(),
1000+
e.what());
1001+
} catch (const std::bad_alloc&) {
1002+
// Ditch logging.. just shut down the connection
1003+
}
1004+
}
1005+
9791006
setState(McbpStateMachine::State::closing);
9801007
/*
9811008
* In addition to setting the state to conn_closing
@@ -986,11 +1013,15 @@ void McbpConnection::runEventLoop(short which) {
9861013
try {
9871014
runStateMachinery();
9881015
} catch (const std::exception& e) {
989-
LOG_WARNING(
990-
"{}: exception occurred in runloop whilst"
991-
" attempting to close connection: {}",
992-
getId(),
993-
e.what());
1016+
try {
1017+
LOG_WARNING(
1018+
"{}: exception occurred in runloop whilst"
1019+
" attempting to close connection: {}",
1020+
getId(),
1021+
e.what());
1022+
} catch (const std::bad_alloc&) {
1023+
// Drop logging
1024+
}
9941025
}
9951026
}
9961027

0 commit comments

Comments
 (0)