summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Samuels <richard.l.samuels@gmail.com>2021-10-29 14:43:44 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-29 15:58:54 +0000
commitda1d7ecb54596409a455f1457012d9dafe788d90 (patch)
treec77d9e6df139e7615af60b5a12e52d663e5045e6
parent1ff3afe5a3a3f2ad7f8cfb04dab438e81a3fb555 (diff)
downloadmongo-da1d7ecb54596409a455f1457012d9dafe788d90.tar.gz
SERVER-61096 ResetDbPath sometimes errors while recreating dbpath on Windows
(cherry picked from commit e8aafb99f494c29e6ed05e3696a9cd2bb6b3ea5b)
-rw-r--r--src/mongo/shell/shell_utils_launcher.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/mongo/shell/shell_utils_launcher.cpp b/src/mongo/shell/shell_utils_launcher.cpp
index 8a01b448d03..eb0637fb031 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -908,6 +908,8 @@ BSONObj ResetDbpath(const BSONObj& a, void* data) {
boost::filesystem::remove_all(path);
} catch (const boost::filesystem::filesystem_error&) {
#ifdef _WIN32
+ // A small sleep allows Windows an opportunity to close locked file
+ // handlers, and reduce false errors on remove_all
sleepmillis(100);
boost::filesystem::remove_all(path);
#else
@@ -915,7 +917,18 @@ BSONObj ResetDbpath(const BSONObj& a, void* data) {
#endif
}
}
- boost::filesystem::create_directory(path);
+ try {
+ boost::filesystem::create_directory(path);
+ } catch (const boost::filesystem::filesystem_error&) {
+#ifdef _WIN32
+ // A small sleep allows Windows an opportunity to close locked file
+ // handlers, and reduce false errors on create_directory
+ sleepmillis(100);
+ boost::filesystem::create_directory(path);
+#else
+ throw;
+#endif
+ }
return undefinedReturn;
}