Ensure pipeline is locked during authentication phase

This commit is contained in:
luaneko 2025-01-11 02:43:42 +11:00
parent 137422601b
commit 6f9e9770cf
Signed by: luaneko
GPG Key ID: 406809B8763FF07A

18
wire.ts
View File

@ -8,7 +8,6 @@ import {
from_utf8, from_utf8,
jit, jit,
semaphore, semaphore,
semaphore_fast,
to_base64, to_base64,
to_utf8, to_utf8,
TypedEmitter, TypedEmitter,
@ -684,8 +683,8 @@ function wire_impl(
} }
// https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-PIPELINING // https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-PIPELINING
const rlock = semaphore_fast(); const rlock = semaphore();
const wlock = semaphore_fast(); const wlock = semaphore();
function pipeline<T>( function pipeline<T>(
w: () => void | PromiseLike<void>, w: () => void | PromiseLike<void>,
@ -697,8 +696,8 @@ function wire_impl(
}); });
} }
function pipeline_read<T>(r: () => T | PromiseLike<T>) { async function pipeline_read<T>(r: () => T | PromiseLike<T>) {
return rlock(async function pipeline_read() { using _rlock = await rlock();
try { try {
return await r(); return await r();
} finally { } finally {
@ -710,11 +709,10 @@ function wire_impl(
// ignored // ignored
} }
} }
});
} }
function pipeline_write<T>(w: () => T | PromiseLike<T>) { async function pipeline_write<T>(w: () => T | PromiseLike<T>) {
return wlock(async function pipeline_write() { using _wlock = await wlock();
try { try {
return await w(); return await w();
} finally { } finally {
@ -724,11 +722,13 @@ function wire_impl(
// ignored // ignored
} }
} }
});
} }
// https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-START-UP // https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-START-UP
async function auth() { async function auth() {
using _rlock = await rlock();
using _wlock = await wlock();
await write(StartupMessage, { await write(StartupMessage, {
version: 196608, version: 196608,
params: { params: {