diff options
| author | Patrick Freed <patrick.freed@mongodb.com> | 2024-09-03 16:18:33 -0400 |
|---|---|---|
| committer | MongoDB Bot <mongo-bot@mongodb.com> | 2024-09-03 21:06:06 +0000 |
| commit | bfe17b40c66720d4a42bd6df3d442bb53f7bcba7 (patch) | |
| tree | fb3a5c01c8e88a86421e13671bce79dad77936ad | |
| parent | c64b3e9df7eecd5cff1ac16ea15112dbd0b887d1 (diff) | |
SERVER-94316 Handle and log all exceptions thrown from ServiceEntryPointRouterRole (8.0) (#26704)
GitOrigin-RevId: c23b7c8cd0203f476f5ad50d6ddc14b51fb4aefa
| -rw-r--r-- | src/mongo/rpc/op_legacy_integration_test.cpp | 11 | ||||
| -rw-r--r-- | src/mongo/s/service_entry_point_mongos.cpp | 30 | ||||
| -rw-r--r-- | src/mongo/s/service_entry_point_mongos.h | 3 |
3 files changed, 28 insertions, 16 deletions
diff --git a/src/mongo/rpc/op_legacy_integration_test.cpp b/src/mongo/rpc/op_legacy_integration_test.cpp index 66d051066cb..9deb1b04d34 100644 --- a/src/mongo/rpc/op_legacy_integration_test.cpp +++ b/src/mongo/rpc/op_legacy_integration_test.cpp @@ -234,6 +234,17 @@ TEST(OpLegacy, UnsupportedReadOps) { ASSERT_THROWS(conn->call(opKillCursors), ExceptionForCat<ErrorCategory::NetworkError>); } +TEST(OpLegacy, InvalidNs) { + auto conn = getIntegrationTestConnection(); + + auto msg = makeMessage(dbQuery, [&](BufBuilder& b) { + b.appendNum(0); + b.appendStr("nonullbyte", false); + }); + // Since our request is not able to be parsed, we don't receive a response from the server. + ASSERT_THROWS(conn->call(msg), DBException); +} + TEST(OpLegacy, GenericCommandViaOpQuery) { auto conn = getIntegrationTestConnection(); diff --git a/src/mongo/s/service_entry_point_mongos.cpp b/src/mongo/s/service_entry_point_mongos.cpp index 0a0f0cd9ecf..6619b1c58e9 100644 --- a/src/mongo/s/service_entry_point_mongos.cpp +++ b/src/mongo/s/service_entry_point_mongos.cpp @@ -99,8 +99,8 @@ struct HandleRequest { // Runs on successful execution of `handleRequest`. void onSuccess(const DbResponse&); - // Returns a ready future-chain that handled the request and prepared the response. - Future<DbResponse> run(); + // Handles the request and fully prepares the response. + DbResponse run(); static NamespaceString getNamespaceString(const DbMessage& dbmsg) { if (!dbmsg.messageShouldHaveNs()) @@ -188,23 +188,25 @@ void HandleRequest::onSuccess(const DbResponse& dbResponse) { currentOp->getReadWriteType()); } -Future<DbResponse> HandleRequest::run() { - try { - setupEnvironment(); - auto dbResponse = handleRequest(); - onSuccess(dbResponse); - return dbResponse; - } catch (const DBException& ex) { - auto status = ex.toStatus(); - LOGV2(4879803, "Failed to handle request", "error"_attr = redact(status)); - return status; - } +DbResponse HandleRequest::run() { + setupEnvironment(); + auto dbResponse = handleRequest(); + onSuccess(dbResponse); + return dbResponse; } Future<DbResponse> ServiceEntryPointMongos::handleRequestImpl(OperationContext* opCtx, - const Message& message) noexcept { + const Message& message) try { auto hr = HandleRequest(opCtx, message); return hr.run(); +} catch (const DBException& ex) { + auto status = ex.toStatus(); + LOGV2(4879803, "Failed to handle request", "error"_attr = redact(status)); + return status; +} catch (...) { + auto error = exceptionToStatus(); + LOGV2_FATAL( + 9431601, "Request handling produced unhandled exception", "error"_attr = redact(error)); } Future<DbResponse> ServiceEntryPointMongos::handleRequest(OperationContext* opCtx, diff --git a/src/mongo/s/service_entry_point_mongos.h b/src/mongo/s/service_entry_point_mongos.h index f44944f731f..80ae5618944 100644 --- a/src/mongo/s/service_entry_point_mongos.h +++ b/src/mongo/s/service_entry_point_mongos.h @@ -40,8 +40,7 @@ class ServiceEntryPointMongos final : public ServiceEntryPointImpl { public: using ServiceEntryPointImpl::ServiceEntryPointImpl; - static Future<DbResponse> handleRequestImpl(OperationContext* opCtx, - const Message& request) noexcept; + static Future<DbResponse> handleRequestImpl(OperationContext* opCtx, const Message& request); Future<DbResponse> handleRequest(OperationContext* opCtx, const Message& request) noexcept final; |
