Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VFS raises error when requested to delete a non-existing file #253

Open
rherrmann opened this issue Jan 6, 2024 · 1 comment
Open

VFS raises error when requested to delete a non-existing file #253

rherrmann opened this issue Jan 6, 2024 · 1 comment

Comments

@rherrmann
Copy link
Contributor

In an attempt to test the behaviour of an SQL statement when run in parallel, I tried to execute the statement from multiple workers.

Here is a striped-down version of the code:

// main.ts
import { DB } from "https://deno.land/x/[email protected]/mod.ts";

const filename = "test.sqlite";
const db = new DB(filename);
db.execute("drop table if exists t; create table t (c text);");
const workers: Worker[] = [];
const workerPromises: Promise<void>[] = [];
for (let index = 0; index < 10; index++) {
  const worker = new Worker(
    new URL("./worker.ts", import.meta.url).href,
    { name: "worker " + index, type: "module" },
  );
  const deferred = Promise.withResolvers<void>();
  worker.onmessage = () => deferred.resolve();
  worker.onmessageerror = () => deferred.reject();
  workers.push(worker);
  workerPromises.push(deferred.promise);
}
workers.forEach((worker) => worker.postMessage({ filename }));
await Promise.all(workerPromises);
db.queryEntries("select * from t").forEach((row) => console.log(row));
db.close();
// worker.ts
/// <reference lib="webworker" />
import { DB } from "https://deno.land/x/[email protected]/mod.ts";

self.onmessage = (event) => {
  const { filename } = event.data;
  const db = new DB(filename, { mode: "write" });
  db.query("insert into t (c) values (:c)", { c: "inserted by " + self.name });
  db.close();
  self.postMessage({ done: true });
  self.close();
};

When the VFS is asked to delete a journal file, it raises this error:

error: Uncaught (in worker "worker 1") NotFound: No such file or directory (os error 2): remove 'test.sqlite-journal'
      Deno.removeSync(path);
           ^
    at Object.removeSync (ext:deno_fs/30_fs.js:209:7)
    at js_delete (https://deno.land/x/[email protected]/build/vfs.js:39:12)
    at <anonymous> (wasm://wasm/0028679a:1:5597)
    ...
error: Uncaught (in promise) Error: Unhandled error in child worker.
    at Worker.#pollControl (ext:runtime/11_workers.js:164:19)
    at eventLoopTick (ext:core/01_core.js:182:7)

After reading #240 and #249 I'm uncertain if the code should get thus far. However, the SQLite demo VFS seems to silently ignore request to delete a non-existing file and returns SQLITE_OK (search for demoDelete).

@dyedgreen
Copy link
Owner

dyedgreen commented Jan 6, 2024

Yes, I think this looks like an issue with file locking (I think the denk api is still unstable as well) but essentially it’s currently not really possible to detect locks held by the same deno process.

I feel like failing loudly when there is an unexpected problem like this seems better than to silently ignore the error though? (Eg in this instance you noticed there is an issue with concurrent access from the same process, which might not have been obvious if the error was swallowed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants