|
27 | 27 | * then also delete it in the license file.
|
28 | 28 | */
|
29 | 29 |
|
| 30 | +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault |
| 31 | + |
30 | 32 | #include "mongo/platform/basic.h"
|
31 | 33 |
|
32 | 34 | #include "mongo/shell/shell_utils.h"
|
|
42 | 44 | #include "mongo/shell/shell_utils_extended.h"
|
43 | 45 | #include "mongo/shell/shell_utils_launcher.h"
|
44 | 46 | #include "mongo/util/concurrency/threadlocal.h"
|
| 47 | +#include "mongo/util/log.h" |
45 | 48 | #include "mongo/util/processinfo.h"
|
46 | 49 | #include "mongo/util/quick_exit.h"
|
47 | 50 | #include "mongo/util/text.h"
|
@@ -324,9 +327,39 @@ void ConnectionRegistry::killOperationsOnAllConnections(bool withPrompt) const {
|
324 | 327 |
|
325 | 328 | BSONObj currentOpRes;
|
326 | 329 | conn->runPseudoCommand("admin", "currentOp", "$cmd.sys.inprog", {}, currentOpRes);
|
| 330 | + if (!currentOpRes["inprog"].isABSONObj()) { |
| 331 | + // We don't have permissions (or the call didn't succeed) - go to the next connection. |
| 332 | + continue; |
| 333 | + } |
327 | 334 | auto inprog = currentOpRes["inprog"].embeddedObject();
|
328 |
| - BSONForEach(op, inprog) { |
329 |
| - if (uris.count(op["client"].String())) { |
| 335 | + for (const auto op : inprog) { |
| 336 | + // For sharded clusters, `client_s` is used instead and `client` is not present. |
| 337 | + string client; |
| 338 | + if (auto elem = op["client"]) { |
| 339 | + // mongod currentOp client |
| 340 | + if (elem.type() != String) { |
| 341 | + warning() << "Ignoring operation " << op["opid"].toString(false) |
| 342 | + << "; expected 'client' field in currentOp response to have type " |
| 343 | + "string, but found " |
| 344 | + << typeName(elem.type()); |
| 345 | + continue; |
| 346 | + } |
| 347 | + client = elem.str(); |
| 348 | + } else if (auto elem = op["client_s"]) { |
| 349 | + // mongos currentOp client |
| 350 | + if (elem.type() != String) { |
| 351 | + warning() << "Ignoring operation " << op["opid"].toString(false) |
| 352 | + << "; expected 'client_s' field in currentOp response to have type " |
| 353 | + "string, but found " |
| 354 | + << typeName(elem.type()); |
| 355 | + continue; |
| 356 | + } |
| 357 | + client = elem.str(); |
| 358 | + } else { |
| 359 | + // Internal operation, like TTL index. |
| 360 | + continue; |
| 361 | + } |
| 362 | + if (uris.count(client)) { |
330 | 363 | if (!withPrompt || prompter.confirm()) {
|
331 | 364 | BSONObjBuilder cmdBob;
|
332 | 365 | BSONObj info;
|
|
0 commit comments