Skip to content

Commit

Permalink
qe: Fix timeout errors (#4641)
Browse files Browse the repository at this point in the history
* qe: Fix timeout errors

Problem: we awaited spawned future immediately, which kind of makes
spawn useless, effecctively serializing batch requests instead of
executing them in parallel. Affects only the batches that could not be
compated into a single query.

I struggled to reproduce the error in engine's test suite. I suggest we
test it in client instead.

Fix prisma/prisma#22610

* Fix wasm

* Use spawn_local for WASM branch

* Address more review comments
  • Loading branch information
Serhii Tatarintsev authored Jan 15, 2024
1 parent eba6207 commit 1deed7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions libs/crosstarget-utils/src/native/spawn.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use futures::TryFutureExt;
use std::future::Future;

use crate::common::SpawnError;

pub async fn spawn_if_possible<F>(future: F) -> Result<F::Output, SpawnError>
pub fn spawn_if_possible<F>(future: F) -> impl Future<Output = Result<F::Output, SpawnError>>
where
F: Future + 'static + Send,
F::Output: Send + 'static,
{
tokio::spawn(future).await.map_err(|_| SpawnError)
tokio::spawn(future).map_err(|_| SpawnError)
}
14 changes: 12 additions & 2 deletions libs/crosstarget-utils/src/wasm/spawn.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
use std::future::Future;

use futures::TryFutureExt;
use tokio::sync::oneshot;
use wasm_bindgen_futures::spawn_local;

use crate::common::SpawnError;

pub async fn spawn_if_possible<F>(future: F) -> Result<F::Output, SpawnError>
pub fn spawn_if_possible<F>(future: F) -> impl Future<Output = Result<F::Output, SpawnError>>
where
F: Future + 'static,
{
Ok(future.await)
let (sx, rx) = oneshot::channel();
spawn_local(async move {
let result = future.await;
_ = sx.send(result);
});

rx.map_err(|_| SpawnError)
}

0 comments on commit 1deed7d

Please sign in to comment.