From 157a7f76d5fac5dfb28ab88020e2e92bbf7e1e7f Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 6 Jul 2023 23:27:30 +0200 Subject: [PATCH] use fs to fix EBAD issue with bun --- backend/windmill-worker/src/worker.rs | 10 ++++++---- frontend/src/lib/components/Editor.svelte | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/windmill-worker/src/worker.rs b/backend/windmill-worker/src/worker.rs index 68b1aa0e14..3eaea8e2a5 100644 --- a/backend/windmill-worker/src/worker.rs +++ b/backend/windmill-worker/src/worker.rs @@ -1917,12 +1917,14 @@ async fn handle_bun_job( let spread = args.into_iter().map(|x| x.name).join(","); // logs.push_str(format!("infer args: {:?}\n", start.elapsed().as_micros()).as_str()); + // we cannot use Bun.read and Bun.write because it results in an EBADF error on cloud let wrapper_content: String = format!( r#" import {{ main }} from "./main.ts"; +const fs = require('fs/promises'); -const args = await Bun.file("args.json").json() +const args = await fs.readFile('args.json', {{ encoding: 'utf8' }}).then(JSON.parse) .then(({{ {spread} }}) => [ {spread} ]) BigInt.prototype.toJSON = function () {{ @@ -1933,11 +1935,11 @@ BigInt.prototype.toJSON = function () {{ async function run() {{ let res: any = await main(...args); const res_json = JSON.stringify(res ?? null, (key, value) => typeof value === 'undefined' ? null : value); - await Bun.write("result.json", res_json); + await fs.writeFile("result.json", res_json); process.exit(0); }} run().catch(async (e) => {{ - await Bun.write("result.json", JSON.stringify({{ message: e.message, name: e.name, stack: e.stack }})); + await fs.writeFile("result.json", JSON.stringify({{ message: e.message, name: e.name, stack: e.stack }})); process.exit(1); }}); "#, @@ -1998,7 +2000,7 @@ let child = if !*DISABLE_NSJAIL { .spawn()? } else { let script_path = format!("{job_dir}/wrapper.ts"); - let mut args = vec!["run", &script_path, "--prefer-offline"]; + let args = vec!["run", &script_path, "--prefer-offline"]; Command::new(&*BUN_PATH) .current_dir(job_dir) .env_clear() diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index eeaff3f2ba..508fdd4cdf 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -532,6 +532,8 @@ }, undefined ) + } else { + closeWebsockets() } websocketInterval && clearInterval(websocketInterval)