Skip to content

Commit 4053046

Browse files
committed
Problem: omnigres packages occassionally conflicting
This happens because `pgpm` calls them in parallel threads and they attempt to clone the same Omnigres revision into the same directory at the same time. Solution: punt it with a mutex (and make sure `pgpm` uses threads)
1 parent 3c8798f commit 4053046

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

exe/pgpm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ require "bundler/setup"
55
require "pgpm"
66
require "dry/cli"
77
require "parallel"
8+
require "etc"
89

910
module Pgpm
1011
module CLI
@@ -48,7 +49,7 @@ module Pgpm
4849

4950
# puts "There is no build support for OS distribution `#{os}`"
5051
# exit(1)
51-
pkgs = Parallel.flat_map(packages) do |package|
52+
pkgs = Parallel.flat_map(packages, in_threads: Etc.nprocessors) do |package|
5253
name, version = package.split("@")
5354
version ||= :latest
5455
p = Pgpm::Package[name]
@@ -122,7 +123,7 @@ module Pgpm
122123
Pgpm.load_packages(pkgdir)
123124

124125
query_regexp = Regexp.new(query, "i")
125-
Parallel.filter_map(Pgpm::Package) do |p|
126+
Parallel.filter_map(Pgpm::Package, in_threads: Etc.nprocessors) do |p|
126127
next if p.contrib?
127128

128129
matches = p.all_searchable_texts.any? do |t|

packages/omnigres/extension_discovery.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,27 @@ module Omnigres
77
class ExtensionDiscovery
88
@@extensions = {}
99
@@git_revisions = {}
10+
@mutex = Mutex.new
11+
12+
class << self
13+
attr_reader :mutex # Expose a class-level reader for the mutex
14+
end
1015

1116
def initialize(revision: nil, path: nil)
1217
return if @@extensions[revision]
1318

1419
suffix = revision ? "-#{revision}" : nil
1520
path ||= Pgpm::Cache.directory.join("omnigres#{suffix}")
16-
git =
17-
if File.directory?(path)
18-
::Git.open(path)
19-
else
20-
::Git.clone("https://github.com/omnigres/omnigres", path)
21-
end
22-
git.checkout(revision) if revision
23-
@git = git
21+
self.class.mutex.synchronize do
22+
git =
23+
if File.directory?(path)
24+
::Git.open(path)
25+
else
26+
::Git.clone("https://github.com/omnigres/omnigres", path)
27+
end
28+
git.checkout(revision) if revision
29+
@git = git
30+
end
2431
end
2532

2633
attr_reader :git

0 commit comments

Comments
 (0)