From 7389ca87b3cc9800af5560aa9e7d05ad584ed0d5 Mon Sep 17 00:00:00 2001 From: Ellen Marie Dash Date: Wed, 27 Nov 2024 18:13:56 -0500 Subject: [PATCH] [rubygems/rubygems] Print message when blocking on a file lock. https://github.com/rubygems/rubygems/commit/3ca7ef214c --- lib/rubygems.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 5951dfe05b..ef8abcb855 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -815,7 +815,14 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} File.open(path, mode) do |io| begin - io.flock(File::LOCK_EX) + # Try to get a lock without blocking. + # If we do, the file is locked. + # Otherwise, explain why we're waiting and get a lock, but block this time. + if io.flock(File::LOCK_EX | File::LOCK_NB) != 0 + warn "Waiting for another process to let go of lock: #{path}" + io.flock(File::LOCK_EX) + end + io.puts(Process.pid) rescue Errno::ENOSYS, Errno::ENOTSUP end yield io