🧪 Announcing PicJS: TypeScript/JavaScript support for PocketIC!

Just hit a bug!
ERROR pocket_ic_server::state_api::state: The instance is deleted immediately after an operation. This is a bug!

  • dfx version - 0.24.0
  • pic-js version - 0.10.0-b0

Not much of a trace to go off of. I added a few logs around it, but once before the bug error message appears I see a PocketIC server encountered an error UpdateError { message: "Instance was deleted" } error, and then it repeats infinitely after the bug error message.

 console.log
    after execute topups

      at Object.<anonymous> (cycleops/memory-notification.test.ts:125:15)

  console.log
    after advance time

      at Object.<anonymous> (cycleops/memory-notification.test.ts:128:15)

  console.log
    second to last test

      at Object.<anonymous> (cycleops/memory-notification.test.ts:132:15)

  console.error
    PocketIC server encountered an error UpdateError { message: "Instance was deleted" }

      at intervalMs (../../node_modules/@hadronous/pic/src/http2-client.ts:90:19)
      at async Timeout.runPoll [as _onTimeout] (../../node_modules/@hadronous/pic/src/util/poll.ts:17:24)

2024-11-22T06:36:49.577335Z ERROR pocket_ic_server::state_api::state: The instance is deleted immediately after an operation. This is a bug!
  console.error
    PocketIC server encountered an error UpdateError { message: "Instance was deleted" }

      at intervalMs (../../node_modules/@hadronous/pic/src/http2-client.ts:90:19)
      at async Timeout.runPoll [as _onTimeout] (../../node_modules/@hadronous/pic/src/util/poll.ts:17:24)

  console.error
    PocketIC server encountered an error UpdateError { message: "Instance was deleted" }

  ... this error then repeats forever.

@mraszyk another benefit of official pic-js support - more PocketIC users and testers to find these bugs :muscle:

Edit: I’ve been able to zero in closer to the issue.

The test where it was failing (with the logging above)

it("executes topups successfully", async () => {
  console.log("second to last test");
  expect("ok" in executeTopupsResult).toBe(true);
});

Updating this async test (that really isn’t async) to a synchronous test (i.e. removing the async keyword) allows this test to pass, but then I get this fun error.

Jest did not exit one second after the test run has completed.

'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
TypeError: fetch failed
    at node:internal/deps/undici/undici:13178:13
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async makeRequest (/Users/byronbecker/Workspace/Dfinity_Projects/mvp/node_modules/@hadronous/pic/src/http2-client.ts:59:19)
    at async intervalMs (/Users/byronbecker/Workspace/Dfinity_Projects/mvp/node_modules/@hadronous/pic/src/http2-client.ts:77:21)
    at async Timeout.runPoll [as _onTimeout] (/Users/byronbecker/Workspace/Dfinity_Projects/mvp/node_modules/@hadronous/pic/src/util/poll.ts:17:24) {
  [cause]: Error: connect ECONNREFUSED 127.0.0.1:52977
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16) {
    errno: -61,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 52977
  }
}

For more context, I also spin up pic before every test and tear it down after every test.
Seems like if a test runs too quickly then it’s runs into an issue tearing down or spinning up again.

Edit: ran this test again and am back to the first error. But removing the short test completely gets rid of the error.