diff options
| author | swarmer <[email protected]> | 2025-08-07 10:49:36 +0300 |
|---|---|---|
| committer | swarmer <[email protected]> | 2025-08-07 11:06:46 +0300 |
| commit | 9765bb0d8b628b0dc07af0fe3dda757a900b669c (patch) | |
| tree | 2f2591154501e064a103453c814cf3c3d5466a3d /library/cpp/testing/common/network.cpp | |
| parent | a073958afdf2ff4c71f34b21363d2f271e92dd1f (diff) | |
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
Diffstat (limited to 'library/cpp/testing/common/network.cpp')
| -rw-r--r-- | library/cpp/testing/common/network.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
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 <util/folder/dirut.h> #include <util/folder/path.h> +#include <util/generic/noncopyable.h> #include <util/generic/singleton.h> #include <util/generic/utility.h> #include <util/generic/vector.h> @@ -15,6 +16,7 @@ #include <util/system/error.h> #include <util/system/file_lock.h> #include <util/system/fs.h> +#include <util/system/sysstat.h> #ifdef _darwin_ #include <sys/types.h> @@ -29,7 +31,7 @@ namespace { } \ } while (false) - class TPortGuard : public NTesting::IPort { + class TPortGuard : public NTesting::IPort, TNonCopyable { public: TPortGuard(ui16 port, THolder<TFileLock> 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; |
