Skip to content

Commit

Permalink
fix(vm-runner): Fix statement timeouts in VM playground (#2772)
Browse files Browse the repository at this point in the history
## What ❔

Fixes statement timeout errors in VM playground.

## Why ❔

VM playground uses the replica DB pool, which has statement timeout
configured by default. This timeout is intended for the API server and
doesn't make sense for VM playground. Hence, this PR removes the
statement timeout and allows to configure it for each built DB pool (in
case other components would require similar changes).

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Code has been formatted via `zk fmt` and `zk lint`.
  • Loading branch information
slowli authored Aug 30, 2024
1 parent c3bde47 commit d3cd553
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ impl WiringLayer for VmPlaygroundLayer {
// to DB for querying last processed batch and last ready to be loaded batch.
// - `window_size` connections for running VM instances.
let connection_pool = replica_pool
.get_custom(2 + self.config.window_size.get())
.build(|builder| {
builder
.set_max_size(2 + self.config.window_size.get())
.set_statement_timeout(None);
// Unlike virtually all other replica pool uses, VM playground has some long-living operations,
// so the default statement timeout would only get in the way.
})
.await?;

let cursor = VmPlaygroundCursorOptions {
Expand Down
15 changes: 14 additions & 1 deletion core/node/node_framework/src/implementations/resources/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,20 @@ impl<P: PoolKind> PoolResource<P> {
}

pub async fn get_custom(&self, size: u32) -> anyhow::Result<ConnectionPool<P::DbMarker>> {
let result = self.builder().set_max_size(size).build().await;
self.build(|builder| {
builder.set_max_size(size);
})
.await
}

pub async fn build<F>(&self, build_fn: F) -> anyhow::Result<ConnectionPool<P::DbMarker>>
where
F: FnOnce(&mut ConnectionPoolBuilder<P::DbMarker>),
{
let mut builder = self.builder();
build_fn(&mut builder);
let size = builder.max_size();
let result = builder.build().await;

if result.is_ok() {
let old_count = self.connections_count.fetch_add(size, Ordering::Relaxed);
Expand Down

0 comments on commit d3cd553

Please sign in to comment.