Skip to content

Commit 23f4210

Browse files
shaargtzMongoDB Bot
authored andcommitted
SERVER-102017 [v7.0] Log startup warning when disableJavaScriptJIT is set (#38324)
GitOrigin-RevId: 622bc78cfcd4cf5c676150c0bdb894bf15be0a9c
1 parent df63ed5 commit 23f4210

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* The Javascript Just In Time compiler is deprecated in 7.0.
3+
*
4+
* This test checks that we log the deprecation warning correctly when setting the server parameter
5+
* on startup or on runtime.
6+
*/
7+
(function() {
8+
'use strict';
9+
load("jstests/libs/log.js"); // For findMatchingLogLine.
10+
11+
const dbName = 'testDB';
12+
13+
function checkLogs(db, deprecationMsg, numMatchingLines) {
14+
const globalLogs = db.adminCommand({getLog: 'global'});
15+
const matchingLogLines = [...findMatchingLogLines(globalLogs.log, deprecationMsg)];
16+
assert.eq(matchingLogLines.length, numMatchingLines, matchingLogLines);
17+
}
18+
19+
/**
20+
* This function will test for the logging of the deprecation messages for the disableJavaScriptJIT
21+
* server parameter. The test can run either on mongod or mongos.
22+
*
23+
* db: The specified mongod or mongos.
24+
* deprecationMsg: The expected log message.
25+
* command: The setParameter command.
26+
* shards: The ShardingTest containing the shards that pair up with the mongos. Null by
27+
* default to accomodate for the mongod case.
28+
*/
29+
function deprecationTest(db, deprecationMsg, command, shards = null) {
30+
// We set the parameter on startup so the message should get logged.
31+
checkLogs(db, deprecationMsg, 1);
32+
33+
if (shards) {
34+
// Same as above but in the shards.
35+
checkLogs(shards.shard0.getDB(db), deprecationMsg, 1);
36+
checkLogs(shards.shard1.getDB(db), deprecationMsg, 1);
37+
}
38+
39+
// We change the parameter during runtime to log the message again.
40+
assert.commandWorked(db.adminCommand(command));
41+
checkLogs(db, deprecationMsg, 2);
42+
if (shards) {
43+
// Same as above but in the shards.
44+
assert.commandWorked(shards.shard0.getDB(db).adminCommand(command));
45+
assert.commandWorked(shards.shard1.getDB(db).adminCommand(command));
46+
checkLogs(shards.shard0.getDB(db), deprecationMsg, 2);
47+
checkLogs(shards.shard1.getDB(db), deprecationMsg, 2);
48+
}
49+
}
50+
51+
const deprecationMessage = {
52+
msg: "The Javascript Just In Time compiler is deprecated, and should be disabled " +
53+
"for security reasons. The server parameter will be removed in a future major " +
54+
"version. See https://www.mongodb.com/docs/manual/reference/parameters for " +
55+
"more information."
56+
};
57+
58+
const setParameterCmdObj = {
59+
setParameter: 1,
60+
disableJavaScriptJIT: false
61+
};
62+
63+
jsTest.log('Test standalone');
64+
65+
const standaloneWithKnob = MongoRunner.runMongod({setParameter: {disableJavaScriptJIT: false}});
66+
const standaloneWithKnobDB = standaloneWithKnob.getDB(dbName);
67+
68+
deprecationTest(standaloneWithKnobDB, deprecationMessage, setParameterCmdObj);
69+
70+
MongoRunner.stopMongod(standaloneWithKnob);
71+
72+
jsTest.log('Test sharded');
73+
74+
const shardsWithKnob = new ShardingTest({
75+
shards: 2,
76+
mongos: 1,
77+
other: {
78+
shardOptions: {setParameter: {disableJavaScriptJIT: false}},
79+
mongosOptions: {setParameter: {disableJavaScriptJIT: false}}
80+
}
81+
});
82+
const sessionWithKnob = shardsWithKnob.s.getDB(dbName).getMongo().startSession();
83+
const shardedWithKnobDB = sessionWithKnob.getDatabase(dbName);
84+
85+
deprecationTest(shardedWithKnobDB, deprecationMessage, setParameterCmdObj, shardsWithKnob);
86+
87+
shardsWithKnob.stop();
88+
89+
jsTest.log('Negative tests');
90+
91+
// Now we do negative tests to check that the message isn't logged if we don't set the parameter.
92+
const standaloneWithoutKnob = MongoRunner.runMongod();
93+
const standaloneWithoutKnobDB = standaloneWithoutKnob.getDB(dbName);
94+
95+
checkLogs(standaloneWithoutKnobDB, deprecationMessage, 0);
96+
97+
MongoRunner.stopMongod(standaloneWithoutKnob);
98+
99+
const shardsWithoutKnob = new ShardingTest({
100+
shards: 2,
101+
mongos: 1,
102+
});
103+
const sessionWithoutKnob = shardsWithoutKnob.s.getDB(dbName).getMongo().startSession();
104+
const shardedWithoutKnobDB = sessionWithoutKnob.getDatabase(dbName);
105+
106+
checkLogs(shardedWithoutKnobDB, deprecationMessage, 0);
107+
checkLogs(shardsWithoutKnob.shard0.getDB(shardedWithoutKnobDB), deprecationMessage, 0);
108+
checkLogs(shardsWithoutKnob.shard1.getDB(shardedWithoutKnobDB), deprecationMessage, 0);
109+
110+
shardsWithoutKnob.stop();
111+
})();

src/mongo/db/commands/parameters.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,15 @@ class CmdSet : public BasicCommand {
338338

339339
ServerParameter::Map::const_iterator foundParameter = parameterMap.find(parameterName);
340340

341+
if (parameterName == "disableJavaScriptJIT") {
342+
LOGV2_WARNING(
343+
10201700,
344+
"The Javascript Just In Time compiler is deprecated, and should be disabled "
345+
"for security reasons. The server parameter will be removed in a future major "
346+
"version. See https://www.mongodb.com/docs/manual/reference/parameters for "
347+
"more information.");
348+
}
349+
341350
// Check to see if this is actually a valid parameter
342351
uassert(ErrorCodes::InvalidOptions,
343352
str::stream() << "attempted to set unrecognized parameter [" << parameterName

src/mongo/db/server_options_server_helpers.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ Status validateServerOptions(const moe::Environment& params) {
223223
" and replication.replSet");
224224
}
225225
}
226+
227+
bool disableJavaScriptJITUsed = parameters.find("disableJavaScriptJIT") != parameters.end();
228+
if (disableJavaScriptJITUsed) {
229+
LOGV2_WARNING(
230+
10201701,
231+
"The Javascript Just In Time compiler is deprecated, and should be disabled "
232+
"for security reasons. The server parameter will be removed in a future major "
233+
"version. See https://www.mongodb.com/docs/manual/reference/parameters for "
234+
"more information.");
235+
}
226236
}
227237
if ((params.count("security.authorization") &&
228238
params["security.authorization"].as<std::string>() == "enabled") ||

0 commit comments

Comments
 (0)