miniflare icon indicating copy to clipboard operation
miniflare copied to clipboard

Second request to a DO hangs if installing default Sinon.js fake timer

Open vlovich opened this issue 3 years ago • 1 comments

If I install Sinon.JS fake timer as follows:

    fakeClock = FakeTimers.install({
      toFake: ['setImmediate']
    })
    fakeClock.setSystemTime(1643948235000)

the second request to a DO seems to hang. Since setImmediate is by default hijacked when FakeTimers.install is invoked without arguments this is a problem. Spelunking through the code, it seems like setImmediate is used for DO I/O gates which seems like a likely explanation as to why that happens. Maybe using queueMicrotask and capturing the value in the global scope might avoid problems with fake timers?

vlovich avatar Feb 27 '22 00:02 vlovich

Hey! 👋 Yep, that seems like the problem. I wonder if importing setImmediate directly from the timers built-in module gives you a unmocked version? Could use that instead... 🤔

mrbbot avatar Mar 04 '22 20:03 mrbbot