From a9191dd6ecde1282f13a8fb14149ef689134cd55 Mon Sep 17 00:00:00 2001 From: Zhenya Tikhonov Date: Mon, 20 May 2024 19:35:03 +0400 Subject: [PATCH] fix: fix memory leak if `timeout` is set --- lib/modem.js | 12 +++++------- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/modem.js b/lib/modem.js index 6e60587..b1292ce 100644 --- a/lib/modem.js +++ b/lib/modem.js @@ -283,17 +283,15 @@ Modem.prototype.buildRequest = function (options, context, data, callback) { if (self.connectionTimeout) { connectionTimeoutTimer = setTimeout(function () { debug('Connection Timeout of %s ms exceeded', self.connectionTimeout); - req.abort(); + req.destroy(); }, self.connectionTimeout); } if (self.timeout) { - req.on('socket', function (socket) { - socket.setTimeout(self.timeout); - socket.on('timeout', function () { - debug('Timeout of %s ms exceeded', self.timeout); - req.abort(); - }); + req.setTimeout(self.timeout); + req.on('timeout', function () { + debug('Timeout of %s ms exceeded', self.timeout); + req.destroy(); }); } diff --git a/package-lock.json b/package-lock.json index 18b49d2..ea22821 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "docker-modem", - "version": "5.0.2", + "version": "5.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "docker-modem", - "version": "5.0.2", + "version": "5.0.4", "license": "Apache-2.0", "dependencies": { "debug": "^4.1.1", diff --git a/package.json b/package.json index 31f5540..dfe9e9e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "docker-modem", "description": "Docker remote API network layer module.", - "version": "5.0.3", + "version": "5.0.4", "author": "Pedro Dias ", "maintainers": [ "apocas "