Skip to content

Commit 84bf7bd

Browse files
committed
Don't allow multiple initdb processes on OSX.
Fixes: [initdb:pid(95804)] INFO i.z.t.d.p.embedded.EmbeddedPostgres - 2020-09-17 12:59:51.996 MDT [95916] DETAIL: Failed system call was shmget(key=5432002, size=56, 03600).
1 parent b1e0444 commit 84bf7bd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/io/zonky/test/db/postgres/embedded/EmbeddedPostgres.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ private void lock() throws IOException
237237
}
238238
}
239239

240+
private static final Lock INITDB_LOCK = new ReentrantLock();
241+
240242
private void initdb()
241243
{
242244
final StopWatch watch = new StopWatch();
@@ -246,7 +248,16 @@ private void initdb()
246248
"-A", "trust", "-U", PG_SUPERUSER,
247249
"-D", dataDirectory.getPath(), "-E", "UTF-8"));
248250
args.addAll(createLocaleOptions());
249-
system(INIT_DB, args);
251+
if (SystemUtils.IS_OS_MAC_OSX) {
252+
INITDB_LOCK.lock();
253+
try {
254+
system(INIT_DB, args);
255+
} finally {
256+
INITDB_LOCK.unlock();
257+
}
258+
} else {
259+
system(INIT_DB, args);
260+
}
250261
LOG.info("{} initdb completed in {}", instanceId, watch);
251262
}
252263

0 commit comments

Comments
 (0)