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:21:28 +0000
commite8aafb99f494c29e6ed05e3696a9cd2bb6b3ea5b (patch)
tree18ffacd0be9ce091a11a87fe2b7f3d8398beb9f0
parent573525802dd48e94453fa4b9168dd9505f9dc93a (diff)
downloadmongo-e8aafb99f494c29e6ed05e3696a9cd2bb6b3ea5b.tar.gz
SERVER-61096 ResetDbPath sometimes errors while recreating dbpath on Windows
-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;
}