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

Uncaught (in promise) TimedOut: timed out at async WireProtocol.receive #419

Open
masx200 opened this issue Oct 24, 2024 · 4 comments
Open

Comments

@masx200
Copy link

masx200 commented Oct 24, 2024

Deno 2.0.2

Linux msx-PC 6.9.6-amd64-desktop-rolling #23.01.01.02 SMP PREEMPT_DYNAMIC Tue Jul 23 12:20:02 CST 2024 x86_64 GNU/Linux

error: Uncaught (in promise) TimedOut: timed out
      rr = await this.#rd.read(this.#buf);
           ^
    at async TlsConn.read (ext:deno_net/01_net.js:135:15)
    at async BufReader.read (https://deno.land/std@0.154.0/io/buffer.ts:383:12)
    at async BufReader.readFull (https://deno.land/std@0.154.0/io/buffer.ts:415:20)
    at async WireProtocol.receive (https://deno.land/x/mongo@v0.32.0/src/protocol/protocol.ts:110:28)
  private async receive() {
    if (this.#isPendingResponse) return;
    this.#isPendingResponse = true;
    while (this.#pendingResponses.size > 0) {
      const headerBuffer = await this.read_socket(16);
      if (!headerBuffer) {
        throw new MongoDriverError("Invalid response header");
      }
      const header = parseHeader(headerBuffer);
      let bodyBytes = header.messageLength - 16;
      if (bodyBytes < 0) bodyBytes = 0;
      const bodyBuffer = await this.read_socket(header.messageLength - 16);
      if (!bodyBuffer) {
        throw new MongoDriverError("Invalid response body");
      }
      const reply = deserializeMessage(header, bodyBuffer);
      const pendingMessage = this.#pendingResponses.get(header.responseTo);
      this.#pendingResponses.delete(header.responseTo);
      pendingMessage?.resolve(reply);
    }
    this.#isPendingResponse = false;
  }

  async command<T = Document>(db: string, body: Document): Promise<T[]> {
    const requestId = nextRequestId++;
    const commandTask = {
      requestId,
      db,
      body,
    };

    this.#commandQueue.push(commandTask);
    this.send();

    const pendingMessage = Promise.withResolvers<Message>();
    this.#pendingResponses.set(requestId, pendingMessage);
    this.receive();
    const message = await pendingMessage.promise;

    let documents: T[] = [];

    for (const section of message?.sections!) {
      if ("document" in section) {
        documents.push(section.document as T);
      } else {
        documents = documents.concat(section.documents as T[]);
      }
    }

    return documents;
  }
@masx200 masx200 changed the title Uncaught (in promise) TimedOut: timed out Uncaught (in promise) TimedOut: timed out at async WireProtocol.receive Oct 24, 2024
@masx200
Copy link
Author

masx200 commented Oct 24, 2024

Uncaught (in promise) cause process exit?

@lucsoft
Copy link
Collaborator

lucsoft commented Oct 24, 2024

We do not handle reconnects currently.

@masx200
Copy link
Author

masx200 commented Oct 24, 2024

We do not handle reconnects currently.

It is not a matter of connection timeouts, but rather an error that does not catch and causes the program to exit.

@lucsoft
Copy link
Collaborator

lucsoft commented Oct 24, 2024

well there is a darft PR about your issue atleast #401

For a workaround i would recommend using docker or systemd with auto restarts/health checks so if your connection drops out your service is not down

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