summaryrefslogtreecommitdiff
path: root/src/mongo/shell
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:24 +0000
commite3f96e7744e17dba8d015e5119fb83318e1d145e (patch)
tree8396d31bd634c94b091a23385bdb2404e2d18d19 /src/mongo/shell
parent8ec8ca3f33e5d6daca6eeb6af7465b33eb7f3242 (diff)
downloadmongo-e3f96e7744e17dba8d015e5119fb83318e1d145e.tar.gz
SERVER-61096 ResetDbPath sometimes errors while recreating dbpath on Windows
(cherry picked from commit e8aafb99f494c29e6ed05e3696a9cd2bb6b3ea5b)
Diffstat (limited to 'src/mongo/shell')
-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 7c475fcb3b1..e4d6560f8fb 100644
--- a/src/mongo/shell/shell_utils_launcher.cpp
+++ b/src/mongo/shell/shell_utils_launcher.cpp
@@ -907,6 +907,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
@@ -914,7 +916,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;
}