Skip to content

Commit b147af9

Browse files
committed
Update
1 parent 7a446c7 commit b147af9

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

ALICE3/Core/GeometryContainer.cxx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sys/file.h>
2828
#include <sys/stat.h>
2929

30+
#include <cerrno>
3031
#include <chrono>
3132
#include <fstream>
3233
#include <map>
@@ -169,15 +170,43 @@ std::string GeometryEntry::accessFile(const std::string& path, const std::string
169170
return localPath;
170171
}
171172

172-
// Try to acquire exclusive lock (blocks until available)
173-
LOG(info) << " --- Acquiring lock for: " << localPath;
174-
if (flock(lockFd, LOCK_EX) == -1) {
173+
// Try to acquire exclusive lock (non-blocking)
174+
LOG(info) << " --- Attempting to acquire lock for: " << localPath;
175+
int lockResult = flock(lockFd, LOCK_EX | LOCK_NB);
176+
177+
if (lockResult == -1 && errno == EWOULDBLOCK) {
178+
// Lock is held by another process - wait up to 10 minutes for download to complete
179+
LOG(info) << " --- Lock is held by another process. Waiting for download to complete (up to 10 minutes)...";
180+
close(lockFd);
181+
182+
const auto startTime = std::chrono::steady_clock::now();
183+
const auto timeout = std::chrono::minutes(10);
184+
const auto checkInterval = std::chrono::seconds(5);
185+
186+
while (true) {
187+
// Check if download is complete
188+
if (stat(doneFile.c_str(), &buffer) == 0) {
189+
LOG(info) << " --- Geometry configuration file was downloaded by another process: " << localPath;
190+
return localPath;
191+
}
192+
193+
// Check timeout
194+
auto elapsed = std::chrono::steady_clock::now() - startTime;
195+
if (elapsed >= timeout) {
196+
LOG(fatal) << " --- Timeout waiting for geometry file download: " << localPath << ". Waited for 10 minutes.";
197+
return localPath;
198+
}
199+
200+
// Wait before checking again
201+
std::this_thread::sleep_for(checkInterval);
202+
}
203+
} else if (lockResult == -1) {
175204
LOG(error) << " --- Failed to acquire lock for: " << lockFile;
176205
close(lockFd);
177206
return localPath;
178207
}
179208

180-
// Double-check if file was downloaded while waiting for lock
209+
// Lock acquired successfully - double-check if file was downloaded while we were trying
181210
if (stat(doneFile.c_str(), &buffer) == 0) {
182211
LOG(info) << " --- Geometry configuration file was downloaded by another process: " << localPath;
183212
flock(lockFd, LOCK_UN);

0 commit comments

Comments
 (0)