fix: remove Spi subtransaction for GUC reads to avoid memory corruption under concurrent load

This commit is contained in:
2026-06-05 19:12:07 -04:00
parent 271828ebe9
commit 532bd8da43

View File

@ -152,44 +152,40 @@ impl DatabaseExecutor for SpiExecutor {
}
fn auth_origin(&self) -> Result<Option<Value>, String> {
self.transact(|| {
Spi::connect(|client| {
let mut tup_table = client
.select(
"SELECT NULLIF(current_setting('auth.origin', true), '')::jsonb",
None,
&[],
)
.map_err(|e| format!("SPI Select Error: {}", e))?;
Spi::connect(|client| {
let mut tup_table = client
.select(
"SELECT NULLIF(current_setting('auth.origin', true), '')::jsonb",
None,
&[],
)
.map_err(|e| format!("SPI Select Error: {}", e))?;
if let Some(row) = tup_table.next() {
if let Ok(Some(jsonb)) = row.get::<pgrx::JsonB>(1) {
return Ok(Some(jsonb.0));
}
if let Some(row) = tup_table.next() {
if let Ok(Some(jsonb)) = row.get::<pgrx::JsonB>(1) {
return Ok(Some(jsonb.0));
}
Ok(None)
})
}
Ok(None)
})
}
fn punc_trigger(&self) -> Result<Option<String>, String> {
self.transact(|| {
Spi::connect(|client| {
let mut tup_table = client
.select(
"SELECT NULLIF(current_setting('punc.name', true), '')",
None,
&[],
)
.map_err(|e| format!("SPI Select Error: {}", e))?;
Spi::connect(|client| {
let mut tup_table = client
.select(
"SELECT NULLIF(current_setting('punc.name', true), '')",
None,
&[],
)
.map_err(|e| format!("SPI Select Error: {}", e))?;
if let Some(row) = tup_table.next() {
if let Ok(val_opt) = row.get::<String>(1) {
return Ok(val_opt);
}
if let Some(row) = tup_table.next() {
if let Ok(val_opt) = row.get::<String>(1) {
return Ok(val_opt);
}
Ok(None)
})
}
Ok(None)
})
}
}