From 4830ff5fda42c0cd6d5a646f6a34ed72b6fae58b Mon Sep 17 00:00:00 2001 From: Yanlong Wang Date: Sat, 8 Mar 2025 21:37:55 +0800 Subject: [PATCH] fix: potential fix for firestore grpc connection reset --- Dockerfile | 2 +- src/api/crawler.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c63914f..1c16980 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 FROM lwthiker/curl-impersonate:0.6-chrome-slim-bullseye -FROM node:20 +FROM node:22 RUN apt-get update \ && apt-get install -y wget gnupg \ diff --git a/src/api/crawler.ts b/src/api/crawler.ts index c741e5c..594d683 100644 --- a/src/api/crawler.ts +++ b/src/api/crawler.ts @@ -519,7 +519,19 @@ export class CrawlerHost extends RPCHost { async queryCache(urlToCrawl: URL, cacheTolerance: number) { const digest = this.getUrlDigest(urlToCrawl); - const cache = (await Crawled.fromFirestoreQuery(Crawled.COLLECTION.where('urlPathDigest', '==', digest).orderBy('createdAt', 'desc').limit(1)))?.[0]; + const cache = ( + await + (Crawled.fromFirestoreQuery( + Crawled.COLLECTION.where('urlPathDigest', '==', digest).orderBy('createdAt', 'desc').limit(1) + ).catch((err) => { + this.logger.warn(`Failed to query cache, unknown issue`, { err }); + // https://github.com/grpc/grpc-node/issues/2647 + // https://github.com/googleapis/nodejs-firestore/issues/1023 + // https://github.com/googleapis/nodejs-firestore/issues/1023 + + return undefined; + })) + )?.[0]; if (!cache) { return undefined;