Skip to content

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

@masx200

Description

@masx200

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;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions