[SERVER-46009] CommandHelpers::canUseTransactions() doesn't guard against uninitialized FCV Created: 06/Feb/20  Updated: 29/Oct/23  Resolved: 20/Feb/20

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 4.3.4

Type: Bug Priority: Major - P3
Reporter: Kevin Pulo Assignee: Maria van Keulen
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-44139 Allow collection creation inside a mu... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Execution Team 2020-02-24
Participants:

 Description   

I hit this by fluke while testing unrelated changes. I happened to be running jstests/noPassthrough/router_transactions_metrics.js, but I suspect other places can cause it. No repro, but the backtrace shows the problem clearly enough.

[js_test:router_transactions_metrics] 2020-02-06T23:10:09.352+1100 d20021| 2020-02-06T23:10:09.352+1100 I  NETWORK  [conn2] received client metadata from 127.0.0.1:41438 conn2: { driver: { name: "NetworkInterfaceTL", version: "0.0.0" }, os: { type: "Linux", name: "Ubuntu", architecture: "x86_64", version: "18.04" } }
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.353+1100 c20022| 2020-02-06T23:10:09.352+1100 I  NETWORK  [listener] connection accepted from 127.0.0.1:43358 #3 (3 connections now open)
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.353+1100 d20021| 2020-02-06T23:10:09.352+1100 F  -        [conn2] Invariant failure isVersionInitialized() src/mongo/db/server_options.h 219
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.353+1100 d20021| 2020-02-06T23:10:09.352+1100 F  -        [conn2]
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.353+1100 d20021|
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.353+1100 d20021| ***aborting after invariant() failure
...
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.590+1100 2020-02-06T23:10:09.590+1100 I  NETWORK  [js] DBClientConnection failed to receive message from 127.0.0.1:20021 - HostUnreachable: Connection closed by peer
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 2020-02-06T23:10:09.591+1100 E  QUERY    [js] uncaught exception: Error: error doing query: failed: network error while attempting to run command 'serverStatus' on host '127.0.0.1:20021'
:
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 DB.prototype.runCommand@src/mongo/shell/db.js:169:19
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 Mongo.prototype.adminCommand@src/mongo/shell/mongo.js:149:12
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 _isRunningWithoutJournaling/result<@src/mongo/shell/replsettest.js:182:53
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 asCluster@src/mongo/shell/replsettest.js:173:20
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 _isRunningWithoutJournaling@src/mongo/shell/replsettest.js:181:22
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 ReplSetTest/this._updateConfigIfNotDurable@src/mongo/shell/replsettest.js:1060:13
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 ReplSetTest/this._setDefaultConfigOptions@src/mongo/shell/replsettest.js:1069:9
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 ReplSetTest/this.initiateWithAnyNodeAsPrimary@src/mongo/shell/replsettest.js:1124:9
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.591+1100 ShardingTest@src/mongo/shell/shardingtest.js:1463:13
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.592+1100 @jstests/noPassthrough/router_transactions_metrics.js:199:12
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.592+1100 @jstests/noPassthrough/router_transactions_metrics.js:4:2
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.592+1100 2020-02-06T23:10:09.591+1100 F  -        [main] failed to load: jstests/noPassthrough/router_transactions_metrics.js
[js_test:router_transactions_metrics] 2020-02-06T23:10:09.592+1100 2020-02-06T23:10:09.591+1100 E  -        [main] exiting with code -3

The line numbers in the backtrace are a bit off because of my local changes.

...
.../src/mongo/util/assert_util.cpp:106:15: mongo::invariantFailed(char const*, char const*, unsigned int)
.../src/mongo/util/invariant.h:69:33: void mongo::invariantWithLocation<bool>(bool const&, char const*, char const*, unsigned int)
.../src/mongo/db/server_options.h:219:13: mongo::ServerGlobalParams::FeatureCompatibility::getVersion() const
.../src/mongo/db/commands.cpp:461:60: mongo::CommandHelpers::canUseTransactions(mongo::NamespaceString const&, mongo::StringData, bool) (.cold.714)
.../src/mongo/db/transaction_validation.cpp:90:43: mongo::validateSessionOptions(mongo::OperationSessionInfoFromClient const&, mongo::StringData, mongo::NamespaceString const&, bool)
.../src/mongo/db/service_entry_point_common.cpp:834:31: execCommandDatabase
...

But anyway, this is the problem and its fix, introduced on cb293d4de806 on SERVER-44139:

diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 338b427e024..9117b157891 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -455,7 +455,8 @@ void CommandHelpers::canUseTransactions(const NamespaceString& nss,
     auto inTxnWhitelist = txnCmdWhitelist.find(cmdName) != txnCmdWhitelist.cend();
     auto inTxnWhitelistFCV44 = txnCmdWhitelistFCV44.find(cmdName) != txnCmdWhitelistFCV44.cend();
     auto isFullyUpgradedTo44 =
-        (serverGlobalParams.featureCompatibility.getVersion() ==
+        (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+         serverGlobalParams.featureCompatibility.getVersion() ==
          ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44);
 
     uassert(ErrorCodes::OperationNotSupportedInTransaction,



 Comments   
Comment by Githook User [ 20/Feb/20 ]

Author:

{'name': 'Maria van Keulen', 'username': 'mvankeulen94', 'email': 'maria.vankeulen@mongodb.com'}

Message: SERVER-46009 Guard against uninitialized FCV during txns checks
Branch: master
https://github.com/mongodb/mongo/commit/ca7d3f919a8466e2977fe3f865a7440b1f846c88

Comment by Maria van Keulen [ 06/Feb/20 ]

Thanks for the heads up, kevin.pulo. The fix makes sense to me, since running multi-document transactions in general before the featureCompatibilityVersion is initialized seems dubious.

Generated at Thu Feb 08 05:10:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.