diff options
author | Jason Carey <jcarey@argv.me> | 2019-03-05 12:32:07 -0500 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2019-03-06 11:54:28 -0500 |
commit | 39b7722f44e2124ad46c19f95d4059985e7d4132 (patch) | |
tree | 7ac6fa40c1a693cd302e4701c76584013d57c7ba | |
parent | 5926b6e06fec4f37e13740dc2eef8b5c7a806138 (diff) | |
download | mongo-39b7722f44e2124ad46c19f95d4059985e7d4132.tar.gz |
SERVER-38175 invariant on markKill w extra info
The OperationContext class accepts an ErrorCodes::Error for markKilled()
and deadline-setting methods. This error code may be converted to a
Status object on checkForInterruptNoAssert() or
waitForConditionOrInterruptNoAssertUntil() call. When the error code is
one that is associated with an ErrorExtraInfo object, Status
construction will fail as we expect Status construction to either
include a subclass of ErrorExtraInfo or a BSONObj from which it can be
serialized.
Until a use case comes up, add an invariant to prevent passing an error
code with extra info
-rw-r--r-- | src/mongo/db/operation_context.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/operation_context_test.cpp | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/mongo/db/operation_context.cpp b/src/mongo/db/operation_context.cpp index 8e27a84b189..271ea547fa2 100644 --- a/src/mongo/db/operation_context.cpp +++ b/src/mongo/db/operation_context.cpp @@ -93,6 +93,7 @@ void OperationContext::setDeadlineAndMaxTime(Date_t when, ErrorCodes::Error timeoutError) { invariant(!getClient()->isInDirectClient() || _hasArtificialDeadline); invariant(ErrorCodes::isExceededTimeLimitError(timeoutError)); + invariant(!ErrorExtraInfo::parserFor(timeoutError)); uassert(40120, "Illegal attempt to change operation deadline", _hasArtificialDeadline || !hasDeadline()); @@ -345,6 +346,7 @@ StatusWith<stdx::cv_status> OperationContext::waitForConditionOrInterruptNoAsser void OperationContext::markKilled(ErrorCodes::Error killCode) { invariant(killCode != ErrorCodes::OK); + invariant(!ErrorExtraInfo::parserFor(killCode)); if (killCode == ErrorCodes::ClientDisconnect) { log() << "operation was interrupted because a client disconnected"; diff --git a/src/mongo/db/operation_context_test.cpp b/src/mongo/db/operation_context_test.cpp index 8195a57cf26..998084a74b3 100644 --- a/src/mongo/db/operation_context_test.cpp +++ b/src/mongo/db/operation_context_test.cpp @@ -140,6 +140,22 @@ DEATH_TEST(OperationContextTest, SettingTransactionNumberWithoutSessionIdShouldC opCtx->setTxnNumber(5); } +DEATH_TEST(OperationContextTest, CallingMarkKillWithExtraInfoCrashes, "invariant") { + auto serviceCtx = ServiceContext::make(); + auto client = serviceCtx->makeClient("OperationContextTest"); + auto opCtx = client->makeOperationContext(); + + opCtx->markKilled(ErrorCodes::ForTestingErrorExtraInfo); +} + +DEATH_TEST(OperationContextTest, CallingSetDeadlineWithExtraInfoCrashes, "invariant") { + auto serviceCtx = ServiceContext::make(); + auto client = serviceCtx->makeClient("OperationContextTest"); + auto opCtx = client->makeOperationContext(); + + opCtx->setDeadlineByDate(Date_t::now(), ErrorCodes::ForTestingErrorExtraInfo); +} + TEST(OperationContextTest, OpCtxGroup) { OperationContextGroup group1; ASSERT_TRUE(group1.isEmpty()); |