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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 agions
3
+ Copyright (c) 2025-2026 agions
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -412,18 +412,22 @@ class RemoteLogHandler {
412
412
  'Content-Type': 'application/json'
413
413
  },
414
414
  body: JSON.stringify(entriesToSend),
415
- // 不等待响应,避免阻塞
416
415
  keepalive: true
417
416
  }).catch((err) => {
418
417
  console.error('Failed to send logs to remote server:', err);
418
+ // 防止无限重试 - 如果失败次数过多,丢弃日志
419
+ if (this._sendCount > 10) {
420
+ console.warn('RemoteLogHandler: Max retry exceeded, discarding logs');
421
+ this.queue = []; // 清空队列,避免内存泄漏
422
+ this._sendCount = 0;
423
+ return;
424
+ }
419
425
  // 失败时把日志放回队列,但防止无限增长
420
426
  if (this.queue.length < this.maxQueueSize) {
421
- // 限制放回的数量,防止内存溢出
422
427
  const maxReturn = Math.min(entriesToSend.length, this.maxQueueSize - this.queue.length);
423
428
  const returnedEntries = entriesToSend.slice(0, maxReturn);
424
429
  this.queue = [...returnedEntries, ...this.queue];
425
430
  }
426
- // 重置发送计数,允许后续重试
427
431
  this._sendCount = 0;
428
432
  });
429
433
  }
@@ -2890,8 +2894,8 @@ class OCRProcessor {
2890
2894
  ? JSON.stringify(error)
2891
2895
  : String(error);
2892
2896
  this.options.logger?.(`OCR识别错误: ${errorMessage}`);
2893
- // 返回空对象,避免完全失败
2894
- return {};
2897
+ // 返回 null,让调用方知道识别失败
2898
+ return null;
2895
2899
  }
2896
2900
  }
2897
2901
  /**