Skip to content

Commit

Permalink
Disable dynamic import for unix-dgram causing memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
aungkhant-samsung committed Sep 15, 2022
1 parent 564ac7b commit a0ee55d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
14 changes: 1 addition & 13 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const dgram = require('dgram');
const net = require('net');
const dns = require('dns');
const { PROTOCOL } = require('./constants');

// Imported below, only if needed
let unixDgram;
const unixDgram = require('unix-dgram');

const UDS_PATH_DEFAULT = '/var/run/datadog/dsd.socket';

Expand Down Expand Up @@ -87,16 +85,6 @@ const createUdpTransport = args => {
};

const createUdsTransport = args => {
try {
// This will not always be available, as noted in the error message below
unixDgram = require('unix-dgram'); // eslint-disable-line global-require
} catch (err) {
throw new Error(
'The library `unix_dgram`, needed for the uds protocol to work, is not installed. ' +
'You need to pick another protocol to use hot-shots. ' +
'See the hot-shots README for additional details.'
);
}
const udsPath = args.path ? args.path : UDS_PATH_DEFAULT;
const socket = unixDgram.createSocket('unix_dgram');

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
"lint": "eslint lib/**/*.js test/**/*.js",
"pretest": "npm run lint"
},
"optionalDependencies": {
"unix-dgram": "2.0.x"
},
"optionalDependencies": {},
"devDependencies": {
"eslint": "5.9.x",
"mocha": "6.2.x",
"nyc": "15.x"
},
"license": "MIT",
"dependencies": {}
"dependencies": {
"unix-dgram": "2.0.x"
}
}

0 comments on commit a0ee55d

Please sign in to comment.