workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: JSG lock error when running locally

Open rodbs opened this issue 3 years ago • 27 comments

Which Cloudflare product(s) does this pertain to?

Wrangler

What version of Wrangler are you using?

3.0.0

What operating system are you using?

Windows 10

Describe the Bug

I'm trying to run Remix (1.16.1) on Pages locally (Win10(. It works with Wrangler 2, but after upgrading to Wrangler 3, it doesn't work producing several errors:

[ERROR] No matching export in "../../Users/rodri/AppData/Local/Temp/functionsWorker-0.19168769412996323.mjs" for import "default"

    ../../Users/rodri/AppData/Local/Temp/tmp-22076-Wi4LUibqhmZQ/middleware-insertion.entry.js:2:7:
      2 │ import worker from "C:\\Users\\rodri\\AppData\\Local\\Temp\\functio...
workerd/jsg/jsg.c++:98: error: took recursive isolate lock; kj::getStackTrace() = 7ff7d1b3a54e 7ff7d17baa24 7ff7d19b6e06 7ff7d19ef9ca 7ff7d19ef912 7ff7d15689b5 7ff7d20e7e7e 7ff7d20ad54b 7ff7d179281a 7ff7d16a3a01 7ff7d1d7eebf 7ff7d16a3a01 7ff7d1d7f80c 7ff7d16a3a01 7ff7d090c23c 7ff7d16a5f12 7ff7d16a3a01 7ff7d090c23c 7ff7d16a4e24 7ff7d16a3a01 7ff7d1a9eefc 7ff7d16a3a01 7ff7d090c23c 7ff7d16a4e24 7ff7d16a3a01 7ff7d1a9f6bc 7ff7d16a3a01 7ff7d1aa039c 7ff7d16a4e24 7ff7d16a3a01

rodbs avatar May 18 '23 21:05 rodbs

I get the same error intermittently on macOS with remix-run 1.16.1

workerd/jsg/jsg.c++:98: error: took recursive isolate lock; kj::getStackTrace() = 10b4d7c39 10b808f12 10b832f01 10b832e86 10cf8e7af 10bb4fe3d 10ba9a895 10ba9aab2 10cf598a2 10b93d4c1 10cf59c92 10b93df91 10cf59c92 10b7e7741 10cf5b973 10cf59c92 10b7e8651 10cf5ab23 10cf598a2 10b7e94a1 10cf59c92 10b7e95c1 10cf5ab23 10cf598a2 10b7e9ac1 10cf59c92 10b

Jackardios avatar May 20 '23 14:05 Jackardios

I ran into this too.

workerd/jsg/jsg.c++:98: error: took recursive isolate lock; kj::getStackTrace() = 104fcf23b 10526d2c7 10528fb53 10528fad7 1066abd8f 1054fd0b3 10546828b 1054684b3 10667e61b 10535a2ab 10667e943 10535ad97 10667e943 10525262f 1066802c3 10667e943 105253223 10667f5ef 10667e61b 105253e57 10667e943 105253f83 10667f5ef 10667e61b 105254367 10667e943 105255607 10667f5ef 10667e61b

I am running MacOS, wrangler 3.0.0. I managed to trigger this by ingesting a number of events in a queue and they all read-write from KV in some way. Nothing unreasonable, and I know this process works in the actual remote cloudflare environment. It also worked in wrangler v2.

Edit: In case it's a point of curiosity, I wasn't running remix at all, this was all cloudflare workers running locally.

AdiRishi avatar May 21 '23 13:05 AdiRishi

Thanks for reporting this! Would you be able to post a minimal reproduction, and we can investigate further?

penalosa avatar May 22 '23 14:05 penalosa

The minimal repo is to create a Remix app on Cloudflare Pages and upgrade it to wrangler 3.0.0. It fails when running it: https://github.com/rodbs/remix-workers

✨ Compiled Worker successfully
 ⛅️ wrangler 3.0.0
------------------
wrangler dev now uses local mode by default, powered by 🔥 Miniflare and 👷 workerd.
To run an edge preview session for your Worker, use wrangler dev --remote
⎔ Starting local server...
▲ [WARNING] Parsed 1 valid header rule.


[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-05-18",
but you've requested "2023-05-22". Falling back to "2023-05-18"...
service core:user:worker: The compatibility flag streams_enable_constructors became the default as of 2022-11-30 so does not need to be specified anymore.
X [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

The error in the first post was when trying to connect to a db to fetch some data.

rodbs avatar May 22 '23 17:05 rodbs

Similar intermittent error upon requests using wrangler 3.0.1 on macOS Ventura 13.3 & 13.4, and using Remix 1.16.1 with the Cloudflare Pages adapter.

workerd/jsg/jsg.c++:133: error: took recursive isolate lock; kj::getStackTrace() = 102beb23b 102e8c017 102eaef97 102eaef1b 1042d7e03 103123e0b 10308b88f 10308bab7 1042aa68f 102f7b98b 1042aa9b7 102f7c477 1042aa9b7 102e71257 1042ac337 1042aa9b7 102e71e4b 1042ab663 1042aa68f 102e72a7f 1042aa9b7 102e72bab 1042ab663 1042aa68f 102e72f8f 1042aa9b7 102e7422f 1042ab663 1042aa68f

patsaas avatar May 22 '23 23:05 patsaas

Same for me in a cloudflare worker / proxy project using wrangler 3.0.1 with local development:

workerd/jsg/jsg.c++:98: error: took recursive isolate lock; kj::getStackTrace() = 106a8bc39 106dbcf12 106de6f01 106de6e86 1085427af 1074f6963 108518c73 108565925 108510630 10850d8a2 106de7bc1 10850d8a2 1074ee8a1 10850dc92 1074ee4c1 1085134ce 10850d8a2 1074edeb1 1074edd1e 1074edfdf 106f5ae5f 106f62a4f 106f629b8 106d700fe 106f6456c 1077cfb6f 1077cf6f9 1077cee35 1076662f4

uname: Darwin jess.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 x86_6

jbergstroem avatar May 25 '23 16:05 jbergstroem

Same for me with wrangler 3.0.1 and macOS 13.4 Beta (22F5037d)

workerd/jsg/jsg.c++:133: error: took recursive isolate lock; kj::getStackTrace() = 102b6723b 102e08017 102e2af97 102e2af1b 104253e03 10309fe0b 10300788f 103007ab7 10422668f 102ef798b 1042269b7 102ef8477 1042269b7 102ded257 104228337 1042269b7 102dede4b 104227663 10422668f 102deea7f 1042269b7 102deebab 104227663 10422668f 102deef8f 1042269b7 102df022f 104227663 10422668f

Usually in comparison with streaming, as in const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); while (true) { const { value, done } = await reader.read(); (...)

mjaskolski avatar May 29 '23 00:05 mjaskolski

running into the same issue running CF worker on macOS Apple M2 Pro chip with Ventura 13.3.1

seems to happen intermittently when calling the same endpoint that returns a stream from OpenAI

bardia-pourvakil avatar Jun 21 '23 18:06 bardia-pourvakil

also getting this, Ventura 13.4.1, wrangler 3.1.1

aroman avatar Jun 25 '23 10:06 aroman

Just upgraded to Remix 1.18.0 with wrangler 3.1.1 and still getting the error:

service core:user:worker: Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.
  at 6efkc5hzhoc.js:63911:24 in FSWatcher2._this._persist
  at 6efkc5hzhoc.js:63926:140 in FSWatcher2.start
  at 6efkc5hzhoc.js:63742:22 in Volume2.watch
  at 6efkc5hzhoc.js:64033:7 in watchStdo
  at 6efkc5hzhoc.js:64029:1
X [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

rodbs avatar Jun 27 '23 10:06 rodbs

I can confirm this is still happening, wrangler@beta and running Arch Linux. workerd/jsg/jsg.c++:133: error: took recursive isolate lock; kj::getStackTrace() =

agarleanu avatar Jun 30 '23 13:06 agarleanu

i got this too wrangler v3.1.1

workerd/jsg/jsg.c++:133: error: took recursive isolate lock; kj::getStackTrace() = 10282b23b 102acc017 102aeef97 102aeef1b 103f17e03 102d63e0b 102ccb88f 102ccbab7 103eea68f 102bbb98b 103eea9b7 102bbc477 103eea9b7 102ab1257 103eec337 103eea9b7 102ab1e4b 103eeb663 103eea68f 102ab2a7f 103eea9b7 102ab2bab 103eeb663 103eea68f 102ab2f8f 103eea9b7

bhirmbani avatar Jul 01 '23 14:07 bhirmbani

I'm getting the same error with Wrangler v3.1.1/macOS 13.4.1 (arm)

workerd/jsg/jsg.c++:133: error: took recursive isolate lock; kj::getStackTrace() = 10462323b 1048c4017 1048e6f97 1048e6f1b 105d0fe03 104b5be0b 104ac388f 104ac3ab7 105ce268f 1049b398b 105ce29b7 1049b4477 105ce29b7 1048a9257 105ce4337 105ce29b7 1048a9e4b 105ce3663 105ce268f 1048aaa7f 105ce29b7 1048aabab 105ce3663 105ce268f 1048aaf8f 105ce29b7 1048ac22f 105ce3663 105ce268f

tcornolti avatar Jul 01 '23 16:07 tcornolti

I'm getting the same error with wrangler v3.2.0 running on linux_64 workerd/jsg/jsg.c++:133: error: took recursive isolate lock; kj::getStackTrace() = 168bbf9 1918fe0 19502a5 1950206 31bc45f 1f50190 3191a13 31df485 3191cb4 318ec22 1950f01 318ec22 2197d9e 318f022 21979c1 18982ff 318ec22 21977b1 219761e 21978da 19d7d7a 1d32f0f

gp27 avatar Jul 13 '23 18:07 gp27

Just upgraded to Remix 1.18.0 with wrangler 3.1.1 and still getting the error:

service core:user:worker: Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.
  at 6efkc5hzhoc.js:63911:24 in FSWatcher2._this._persist
  at 6efkc5hzhoc.js:63926:140 in FSWatcher2.start
  at 6efkc5hzhoc.js:63742:22 in Volume2.watch
  at 6efkc5hzhoc.js:64033:7 in watchStdo
  at 6efkc5hzhoc.js:64029:1
X [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.

FYI @rodbs, that specific error is probably https://github.com/remix-run/remix/issues/6665.

aaronadamsCA avatar Jul 17 '23 16:07 aaronadamsCA

This error occurs for me without Remix.

export default {
	async fetch() {
		await fetch("https://google.com.au/");

		return new Response("Hello, world!");
	},
} satisfies ExportedHandler;

I use NixOS, and have created a reproduction at scottwillmoore/cloudflare-workers-with-nix, although I don't know if it will help much as Nix can be difficult to use for first-time users.

EDIT: My reproduction uses [email protected].

scottwillmoore avatar Jul 20 '23 00:07 scottwillmoore

Oh, I should mention, I do get this error intermittently too, on Ubuntu 22.04.2 LTS. Wrangler v3.2.0, under Remix with command wrangler pages dev public/ --compatibility-date=2023-03-14 --kv=KV_SESSIONS --local-protocol=https.

aaronadamsCA avatar Jul 20 '23 00:07 aaronadamsCA

@scottwillmoore try env.ASSETS.fetch instead of fetch, solved it for me.

chr33s avatar Jul 26 '23 03:07 chr33s

@chr33s The env.ASSETS.fetch function is for Cloudflare Pages and used for local assets right? I didn't spend much time looking into it, but it didn't work to replace my use-case of fetch. I am also not using Cloudflare Pages and my request is for https://google.com.au/ (not local assets).

scottwillmoore avatar Jul 30 '23 02:07 scottwillmoore

This is more of a warning than an error; nothing will actually go wrong.

https://github.com/cloudflare/workerd/issues/706#issuecomment-1638272710

I see lots of these warnings when making multiple requests to the Cache API

jacobpake avatar Jul 30 '23 15:07 jacobpake