prisma: Flaky `Engine is not yet connected.` CI test with Node-API

Bug description

This test is flaky with Node-API

FAIL src/__tests__/integration/happy/disconnect-while-query/test.ts
  ✕ disconnect-while-query (770 ms)
  ● disconnect-while-query
    Invalid `prisma.user.findMany()` invocation in
    /home/runner/work/prisma/prisma/src/packages/client/src/__tests__/integration/happy/disconnect-while-query/test.ts:8:25
       5 const prisma = new PrismaClient()
       6 
       7 await prisma.user.findMany()
    →  8 const a = prisma.user.findMany(
      Engine is not yet connected.
       0: user_facing_errors::Error::new_non_panic_with_current_backtrace
       1: query_engine_napi::error::<impl core::convert::From<query_engine_napi::error::ApiError> for user_facing_errors::Error>::from
       2: query_engine_napi::error::<impl core::convert::From<query_engine_napi::error::ApiError> for napi::error::Error>::from
       3: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
       4: tokio::runtime::task::core::CoreStage<T>::poll
       5: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
       6: tokio::runtime::task::harness::poll_future
       7: tokio::runtime::task::harness::Harness<T,S>::poll
       8: std::thread::local::LocalKey<T>::with
       9: tokio::runtime::thread_pool::worker::Context::run_task
      10: tokio::runtime::thread_pool::worker::Context::run
      11: tokio::macros::scoped_tls::ScopedKey<T>::set
      12: tokio::runtime::thread_pool::worker::run
      13: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
      14: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
      15: tokio::runtime::task::harness::Harness<T,S>::poll
      16: tokio::runtime::blocking::pool::Inner::run
      17: std::sys_common::backtrace::__rust_begin_short_backtrace
      18: core::ops::function::FnOnce::call_once{{vtable.shim}}
      19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
      at ../../../../../../../../rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/alloc/src/boxed.rs:1521:9
            <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
      at ../../../../../../../../rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/alloc/src/boxed.rs:1521:9
            std::sys::unix::thread::Thread::new::thread_start
      at ../../../../../../../../rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/std/src/sys/unix/thread.rs:71:17
        20: start_thread
        21: clone
      at cb (src/runtime/PrismaClientFetcher.ts:172:17)

In Github Actions: https://github.com/prisma/prisma/pull/7566/checks?check_run_id=2783712904#step:8:1202

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

For my case the problem happened after I did

arr.forEach((e)=> {
    await prisma.recipe.create(e)
})

But got fixed after I did

 for (let i = 0; i < arr.length; i++) {
        const e = arr[i];
        await prisma.recipe.create(e)
 }

I found that new flaky tests have been detected around this (via disconnect-while-query test) https://buildpulse.io/@prisma/prisma/tests/2892009034

PrismaClientUnknownRequestError: 
Invalid `prisma.user.findMany()` invocation in
D:\a\prisma\prisma\packages\client\src\__tests__\integration\happy\disconnect-while-query\test.ts:8:25

  5 const prisma = new PrismaClient()
  6 
  7 await prisma.user.findMany()
→ 8 const a = prisma.user.findMany(
Engine is not yet connected.
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: napi_register_module_v1
   5: napi_register_module_v1
   6: napi_register_module_v1
   7: napi_register_module_v1
   8: napi_register_module_v1
   9: napi_register_module_v1
  10: BaseThreadInitThunk
  11: RtlUserThreadStart

    at RequestHandler.handleRequestError (D:\a\prisma\prisma\packages\client\src\runtime\RequestHandler.ts:241:13)
    at RequestHandler.handleRequestError [as handleAndLogRequestError] (D:\a\prisma\prisma\packages\client\src\runtime\RequestHandler.ts:183:12)
    at RequestHandler.handleAndLogRequestError [as request] (D:\a\prisma\prisma\packages\client\src\runtime\Request...