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

Client closing leads to BadResource / Interrupted #376

Open
albnnc opened this issue Aug 19, 2022 · 0 comments
Open

Client closing leads to BadResource / Interrupted #376

albnnc opened this issue Aug 19, 2022 · 0 comments

Comments

@albnnc
Copy link
Contributor

albnnc commented Aug 19, 2022

Client closing sometimes leads to the following errors:

  1. BadResource
error: (in promise) BadResource: Bad resource ID
    nwritten += await w.write(arr.subarray(nwritten));
                ^
    at async write (deno:ext/net/01_net.js:33:12)
    at async writeAll (https://deno.land/[email protected]/streams/conversion.ts:422:17)
    at async WireProtocol.send (https://deno.land/x/[email protected]/src/protocol/protocol.ts:101:7)
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.
  1. Interrupted
error: (in promise) Interrupted: operation canceled
      rr = await this.#rd.read(this.#buf);
           ^
    at async read (deno:ext/net/01_net.js:28:19)
    at async BufReader.read (https://deno.land/[email protected]/io/buffer.ts:383:12)
    at async BufReader.readFull (https://deno.land/[email protected]/io/buffer.ts:415:20)
    at async WireProtocol.receive (https://deno.land/x/[email protected]/src/protocol/protocol.ts:110:28)
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

They are, most likely, caused by the fact that send and receive functions never catch anything and their calls (1, 2) don't use catch too.

I'm not quite familiar with this repo, but it looks like one could just catch these errors, which would, however, lead to the scenario when command queue is broken in case of real connection problem. That being said, it looks like this issue is somewhat related to automatic reconnect feature proposal – one should distinct errors occurred during mongoClient.close() calls (and catch them) and other errors (and try to reconnect, probably).

For anyone who want to make own tests less flaky on client close, I can suggest this workaround (one should use this before mongoClient.close()):

addEventListener("unhandledrejection", (e) => {
  if (
    ["BadResource", "Interrupted"].includes(e.reason.name) &&
    e.reason.stack.includes("deno.land/x/mongo")
  ) {
    e.preventDefault();
  }
});

If anyone has better workaround, please write it in this thread.

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

1 participant