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.
This commit is contained in:
Andrew authored and GitHub committed 2026-10-21 08:51:25 -05:00
1 parent 0773f717cd
commit 1bc39fd358
1 file changed
+3 -3
+3 -3
View File
@@ -71,6 +71,7 @@
#if !defined(_WIN32)
#include <unistd.h>
#include <fcntl.h>
#include <sys/file.h>
#include <cerrno>
#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
}