From c5a471b7a89ba6fbdd269177d122abb10195901b Mon Sep 17 00:00:00 2001 From: Rakhi Mundhada Date: Thu, 25 Jul 2024 14:59:19 +0530 Subject: [PATCH] To handle max socket warning while writing the item on DDb --- package.json | 2 +- paws_collector.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6de11fd4..47e0a665 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alertlogic/paws-collector", - "version": "2.2.4", + "version": "2.2.5", "license": "MIT", "description": "Alert Logic AWS based API Poll Log Collector Library", "repository": { diff --git a/paws_collector.js b/paws_collector.js index 426f4389..8ca10cfb 100644 --- a/paws_collector.js +++ b/paws_collector.js @@ -52,10 +52,18 @@ const ERROR_CODE_COMPLETED_STATE = 'COMPLETED_STATE'; const SQS_VISIBILITY_TIMEOUT = 900; const DDB_TTL_DAYS = 14; const DEDUP_LOG_TTL_SECONDS = 86400; +let maxSocket = process.env.maxSocket ? process.env.maxSocket : 100; + +// using short syntax from https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html const DDB_OPTIONS = { maxRetries: 10, - ConsistentRead: true -}; + ConsistentRead: true, + requestHandler: { + httpsAgent: { + maxSockets: maxSocket + } + } +} const DDB_DELETE_BATCH_OPTIONS = { maxBatchSize: 25, maxBatchSizeBytes: 16 * 1024 * 1024 @@ -925,7 +933,7 @@ class PawsCollector extends AlAwsCollector { */ removeDuplicatedItem(logs, paramName, asyncCallback) { let collector = this; - const ddb = new DynamoDB(); + const ddb = new DynamoDB(DDB_OPTIONS); let uniqueLogs = []; var promises = []; let duplicateCount = 0;