From 1bc39fd358a70fdca852f1ebc019391479c8a4d4 Mon Sep 17 00:00:00 2001 From: Andrew <159703254+andrewsoonqn@users.noreply.github.com> Date: Wed, 21 Oct 2026 21:51:25 +0800 Subject: [PATCH] fix: preserve POSIX refresh lock ownership (#14781) Use flock instead of fcntl for the refresh token lock on POSIX. An fcntl lock is held per process, so a second thread took it without waiting, and closing that thread's fd released it for the first thread too. Another Orca instance could then send the same refresh token while the first one was still rotating it. --- src/slic3r/Utils/OrcaCloudServiceAgent.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/slic3r/Utils/OrcaCloudServiceAgent.cpp b/src/slic3r/Utils/OrcaCloudServiceAgent.cpp index f759d15a2b..69686d470e 100644 --- a/src/slic3r/Utils/OrcaCloudServiceAgent.cpp +++ b/src/slic3r/Utils/OrcaCloudServiceAgent.cpp @@ -71,6 +71,7 @@ #if !defined(_WIN32) #include #include +#include #include #endif @@ -145,10 +146,9 @@ public: #else m_fd = ::open(path.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0600); if (m_fd == -1) { m_locked = true; return; } // can't open -> don't block - struct flock fl{}; - fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; int rc; - do { rc = ::fcntl(m_fd, F_SETLKW, &fl); } while (rc == -1 && errno == EINTR); // blocks in kernel + // An fcntl lock would not block other threads in this process, and any close() of this file would release it. + do { rc = ::flock(m_fd, LOCK_EX); } while (rc == -1 && errno == EINTR); // blocks in kernel m_locked = (rc != -1); #endif }