From 9765bb0d8b628b0dc07af0fe3dda757a900b669c Mon Sep 17 00:00:00 2001 From: swarmer Date: Thu, 7 Aug 2025 10:49:36 +0300 Subject: TPortManager shouldn't crash even if it doesn't have enough permissions to operate on lock files created by other users Create the `testing_port_locks` directory with RWX permission for all, allowing other users to create lock files within it. Don't abort if current user doesn't have enough permission to delete a lock file created by another user. KIKIMR-23792 commit_hash:d887ce073d42d93c997a0f9a0c16416860395377 --- library/cpp/testing/common/network.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'library/cpp/testing/common/network.cpp') diff --git a/library/cpp/testing/common/network.cpp b/library/cpp/testing/common/network.cpp index 9f018f69b72..dbc80715fde 100644 --- a/library/cpp/testing/common/network.cpp +++ b/library/cpp/testing/common/network.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #ifdef _darwin_ #include @@ -29,7 +31,7 @@ namespace { } \ } while (false) - class TPortGuard : public NTesting::IPort { + class TPortGuard : public NTesting::IPort, TNonCopyable { public: TPortGuard(ui16 port, THolder lock) : Lock_(std::move(lock)) @@ -38,7 +40,16 @@ namespace { } ~TPortGuard() override { - Y_VERIFY_SYSERROR(NFs::Remove(Lock_->GetName())); + try { + if (!NFs::Remove(Lock_->GetName())) { + // Deletion may fail if the current user does not have + // write permission to the PORT_SYNC_PATH directory. + // At least let's release the lock file. + Lock_->Release(); + } + } catch (const TSystemError& e) { + Y_ABORT("Failed to unlock port %d, error=%d", Port_, e.Status()); + } } ui16 Get() override { @@ -107,6 +118,7 @@ namespace { } Y_ABORT_UNLESS(SyncDir_.IsDefined()); NFs::MakeDirectoryRecursive(SyncDir_); + Chmod(SyncDir_.c_str(), NFs::FP_COMMON_FILE); // override umask Ranges_ = GetPortRanges(); TotalCount_ = 0; -- cgit v1.3