id-scanner-lib 1.6.4 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -414,18 +414,22 @@
414
414
  'Content-Type': 'application/json'
415
415
  },
416
416
  body: JSON.stringify(entriesToSend),
417
- // 不等待响应,避免阻塞
418
417
  keepalive: true
419
418
  }).catch((err) => {
420
419
  console.error('Failed to send logs to remote server:', err);
420
+ // 防止无限重试 - 如果失败次数过多,丢弃日志
421
+ if (this._sendCount > 10) {
422
+ console.warn('RemoteLogHandler: Max retry exceeded, discarding logs');
423
+ this.queue = []; // 清空队列,避免内存泄漏
424
+ this._sendCount = 0;
425
+ return;
426
+ }
421
427
  // 失败时把日志放回队列,但防止无限增长
422
428
  if (this.queue.length < this.maxQueueSize) {
423
- // 限制放回的数量,防止内存溢出
424
429
  const maxReturn = Math.min(entriesToSend.length, this.maxQueueSize - this.queue.length);
425
430
  const returnedEntries = entriesToSend.slice(0, maxReturn);
426
431
  this.queue = [...returnedEntries, ...this.queue];
427
432
  }
428
- // 重置发送计数,允许后续重试
429
433
  this._sendCount = 0;
430
434
  });
431
435
  }
@@ -2892,8 +2896,8 @@
2892
2896
  ? JSON.stringify(error)
2893
2897
  : String(error);
2894
2898
  this.options.logger?.(`OCR识别错误: ${errorMessage}`);
2895
- // 返回空对象,避免完全失败
2896
- return {};
2899
+ // 返回 null,让调用方知道识别失败
2900
+ return null;
2897
2901
  }
2898
2902
  }
2899
2903
  /**