Skip to content

Commit 0e1eb46

Browse files
author
Kanhaiya Lal Singh
authored
Merge pull request #5 from LambdaTest/feature/tunnel-wrapper
Fix process kill and added env for proxy. Fixex tunnel-operations/#101
2 parents 00ec143 + c6f3ecd commit 0e1eb46

File tree

4 files changed

+64
-26
lines changed

4 files changed

+64
-26
lines changed

lib/conf/node-tunnel-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tunnelBinary":{"mac":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"34433fb765db9fe993cc51a79a9dc056"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"6ca43777f406f8d658320f2bf0e57169"}},"win":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"479633a1aa44065814c792b7ddcbe02a"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"2019aeadb57594dca15d9b95fdbbcc69"}},"linux":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"6aebc2fd59120aeb81b8041509713a73"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"af49cab379849f774978fcccb9cb4e33"}},"freebsd":{"32bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"8a6dddd85d37576de4f5dc1bd0e54b4d"},"64bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"c75bae7743d743d0c265118005cb5d6a"}}},"AuthUrl":"https://accounts.lambdatest.com/api/user/token/auth","logEnable":true,"latest":"2.0.1","supportedVersions":["1.0.0","1.0.1","1.0.2","1.0.3","1.0.4","1.0.5","1.0.6","1.0.7","1.0.8","1.0.9","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","2.0.0","2.0.1","2.0.2","2.0.3","2.0.4","2.0.5","2.0.6","2.0.7","2.0.8","2.0.9","2.0.10","2.0.11","2.0.12","2.0.13","2.0.14","2.0.15","2.0.16","2.0.17","2.0.18","2.0.19","2.1.0","2.1.1","2.1.2","2.1.3","2.1.4","2.1.5","2.1.6","2.1.7","2.1.8","2.1.9","2.1.10","2.1.11","2.1.12","2.1.13","2.1.14","2.1.15","2.1.16","2.1.17","2.1.18","2.1.19","2.2.0","2.2.1","2.2.2","2.2.3","2.2.4","2.2.5","2.2.6","2.2.7","2.2.8","2.2.9","2.2.10","2.2.11","2.2.12","2.2.13","2.2.14","2.2.15","2.2.16","2.2.17","2.2.18","2.2.19","2.3.0","2.3.1","2.3.2","2.3.3","2.3.4","2.3.5","2.3.6","2.3.7","2.3.8","2.3.9","2.3.10","2.3.11","2.3.12","2.3.13","2.3.14","2.3.15","2.3.16","2.3.17","2.3.18","2.3.19","2.4.0","2.4.1","2.4.2","2.4.3","2.4.4","2.4.5","2.4.6","2.4.7","2.4.8","2.4.9","2.4.10","2.4.11","2.4.12","2.4.13","2.4.14","2.4.15","2.4.16","2.4.17","2.4.18","2.4.19","2.5.0","2.5.1","2.5.2","2.5.3","2.5.4","2.5.5","2.5.6","2.5.7","2.5.8","2.5.9","2.5.10","2.5.11","2.5.12","2.5.13","2.5.14","2.5.15","2.5.16","2.5.17","2.5.18","2.5.19","2.6.0","2.6.1","2.6.2","2.6.3","2.6.4","2.6.5","2.6.6","2.6.7","2.6.8","2.6.9","2.6.10","2.6.11","2.6.12","2.6.13","2.6.14","2.6.15","2.6.16","2.6.17","2.6.18","2.6.19","2.7.0","2.7.1","2.7.2","2.7.3","2.7.4","2.7.5","2.7.6","2.7.7","2.7.8","2.7.9","2.7.10","2.7.11","2.7.12","2.7.13","2.7.14","2.7.15","2.7.16","2.7.17","2.7.18","2.7.19","2.8.0","2.8.1","2.8.2","2.8.3","2.8.4","2.8.5","2.8.6","2.8.7","2.8.8","2.8.9","2.8.10","2.8.11","2.8.12","2.8.13","2.8.14","2.8.15","2.8.16","2.8.17","2.8.18","2.8.19","2.9.0","2.9.1","2.9.2","2.9.3","2.9.4","2.9.5","2.9.6","2.9.7","2.9.8","2.9.9","2.9.10","2.9.11","2.9.12","2.9.13","2.9.14","2.9.15","2.9.16","2.9.17","2.9.18","2.9.19"]}
1+
{"tunnelBinary":{"mac":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"7e0421e977ed8d46b93180c3f840a5ca"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/LT_Mac.zip","binaryName":"LT_Mac.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/mac/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"8f273e905e9e372f049931f210d3afd0"}},"win":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"e9b4b5095c708ce241c443434038a888"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/LT_Windows.zip","binaryName":"LT_Windows.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/windows/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"9a8012732dbea3bda25d20fec4d4f1c8"}},"linux":{"32bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"78a31c2c5d632863f9d7383933e6627a"},"64bit":{"httpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/LT_Linux.zip","binaryName":"LT_Linux.zip","newHttpPath":"https://downloads.lambdatest.com/tunnel/linux/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"394ac8c32383b8c42842bc4eeb74f901"}},"freebsd":{"32bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/32bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"fec5a4ff0bc682d9e874fc28c1e5ce96"},"64bit":{"newHttpPath":"https://downloads.lambdatest.com/tunnel/freebsd/64bit/ltcomponent.zip","newBinaryName":"ltcomponent.zip","hash":"7ed86881cdb37c9059443789d6e0f982"}}},"AuthUrl":"https://accounts.lambdatest.com/api/user/token/auth","logEnable":true,"latest":"2.0.2","supportedVersions":["1.0.0","1.0.1","1.0.2","1.0.3","1.0.4","1.0.5","1.0.6","1.0.7","1.0.8","1.0.9","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","2.0.0","2.0.1","2.0.2","2.0.3","2.0.4","2.0.5","2.0.6","2.0.7","2.0.8","2.0.9","2.0.10","2.0.11","2.0.12","2.0.13","2.0.14","2.0.15","2.0.16","2.0.17","2.0.18","2.0.19","2.1.0","2.1.1","2.1.2","2.1.3","2.1.4","2.1.5","2.1.6","2.1.7","2.1.8","2.1.9","2.1.10","2.1.11","2.1.12","2.1.13","2.1.14","2.1.15","2.1.16","2.1.17","2.1.18","2.1.19","2.2.0","2.2.1","2.2.2","2.2.3","2.2.4","2.2.5","2.2.6","2.2.7","2.2.8","2.2.9","2.2.10","2.2.11","2.2.12","2.2.13","2.2.14","2.2.15","2.2.16","2.2.17","2.2.18","2.2.19","2.3.0","2.3.1","2.3.2","2.3.3","2.3.4","2.3.5","2.3.6","2.3.7","2.3.8","2.3.9","2.3.10","2.3.11","2.3.12","2.3.13","2.3.14","2.3.15","2.3.16","2.3.17","2.3.18","2.3.19","2.4.0","2.4.1","2.4.2","2.4.3","2.4.4","2.4.5","2.4.6","2.4.7","2.4.8","2.4.9","2.4.10","2.4.11","2.4.12","2.4.13","2.4.14","2.4.15","2.4.16","2.4.17","2.4.18","2.4.19","2.5.0","2.5.1","2.5.2","2.5.3","2.5.4","2.5.5","2.5.6","2.5.7","2.5.8","2.5.9","2.5.10","2.5.11","2.5.12","2.5.13","2.5.14","2.5.15","2.5.16","2.5.17","2.5.18","2.5.19","2.6.0","2.6.1","2.6.2","2.6.3","2.6.4","2.6.5","2.6.6","2.6.7","2.6.8","2.6.9","2.6.10","2.6.11","2.6.12","2.6.13","2.6.14","2.6.15","2.6.16","2.6.17","2.6.18","2.6.19","2.7.0","2.7.1","2.7.2","2.7.3","2.7.4","2.7.5","2.7.6","2.7.7","2.7.8","2.7.9","2.7.10","2.7.11","2.7.12","2.7.13","2.7.14","2.7.15","2.7.16","2.7.17","2.7.18","2.7.19","2.8.0","2.8.1","2.8.2","2.8.3","2.8.4","2.8.5","2.8.6","2.8.7","2.8.8","2.8.9","2.8.10","2.8.11","2.8.12","2.8.13","2.8.14","2.8.15","2.8.16","2.8.17","2.8.18","2.8.19","2.9.0","2.9.1","2.9.2","2.9.3","2.9.4","2.9.5","2.9.6","2.9.7","2.9.8","2.9.9","2.9.10","2.9.11","2.9.12","2.9.13","2.9.14","2.9.15","2.9.16","2.9.17","2.9.18","2.9.19"]}

lib/tunnel.js

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -466,24 +466,39 @@ function killRunningProcess_(that, fnCallback) {
466466
// use try-catch as possibility of Error while killing process.
467467
try {
468468
// Check process is running before killing
469-
if (that.proc) {
470-
that.proc.on('exit', function() {
471-
if (that.proc.pid) {
472-
setTimeout(function() {
473-
try {
474-
process.kill(that.proc.pid);
475-
} catch (err) {}
476-
return fnCallback();
477-
}, 500);
478-
}
479-
return fnCallback();
469+
if (that.proc && that.infoAPIPort) {
470+
var url = 'http://127.0.0.1:' + that.infoAPIPort + '/api/v1.0/stop';
471+
var parseURL = urlParse.parse(url);
472+
var reqOptions = {
473+
hostname: parseURL.hostname,
474+
port: parseURL.port,
475+
path: parseURL.path,
476+
method: 'DELETE'
477+
};
478+
479+
var req = http.request(reqOptions, resp => {
480+
resp.on('data', () => {})
481+
resp.on('end', () => {
482+
if (resp.statusCode != 200) {
483+
killProcess_(that, fnCallback);
484+
}
485+
return fnCallback();
486+
});
480487
});
481-
if (os.platform() == 'win32') {
482-
childProcess.exec('taskkill /F /PID ' + that.proc.pid);
483-
} else {
484-
that.proc.stdin.pause();
485-
that.proc.kill('SIGINT');
486-
}
488+
489+
req.on('error', e => {
490+
killProcess_(that, fnCallback);
491+
logger.log(
492+
that.options['user'],
493+
that.options['key'],
494+
{ filename: __filename },
495+
that.options,
496+
'Getting error while killing the running process. Error : ' + e
497+
);
498+
return fnCallback(e);
499+
});
500+
req.write('');
501+
req.end();
487502
} else {
488503
return fnCallback();
489504
}
@@ -857,5 +872,30 @@ function clearTimeout_(timeoutId) {
857872
clearTimeout(timeoutId);
858873
}
859874
}
875+
/**
876+
* killProcess_ is used to kill process method.
877+
* @param {Object} that is Instance.
878+
* @param {Function} fnCallback is Callback Method.
879+
* @return {null} Return null.
880+
*/
881+
function killProcess_(that, fnCallback) {
882+
that.proc.on('exit', function() {
883+
if (that.proc.pid) {
884+
setTimeout(function() {
885+
try {
886+
process.kill(that.proc.pid);
887+
} catch (err) {}
888+
return fnCallback();
889+
}, 500);
890+
}
891+
return fnCallback();
892+
});
893+
if (os.platform() == 'win32') {
894+
childProcess.exec('taskkill /F /PID ' + that.proc.pid);
895+
} else {
896+
that.proc.stdin.pause();
897+
that.proc.kill('SIGINT');
898+
}
899+
}
860900
module.exports = Tunnel;
861901
module.exports.Tunnel = Tunnel;

lib/util.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ function getProxyOpts_(options) {
1515
host: options.proxyHost,
1616
port: options.proxyPort
1717
};
18-
} else if (process.env.http_proxy) {
19-
proxyOpts = urlParse.parse(process.env.http_proxy);
20-
}
21-
if ((options.proxyUser && !options.proxyPass) || (!options.proxyUser && options.proxyPass)) {
22-
throw Error('proxyUser and proxyPass must be both or none');
23-
} else if (options.proxyUser && options.proxyPass) {
24-
if (Object.keys(proxyOpts).length) {
18+
if ((options.proxyUser && !options.proxyPass) || (!options.proxyUser && options.proxyPass)) {
19+
throw Error('proxyUser and proxyPass must be both or none');
20+
} else if (options.proxyUser && options.proxyPass) {
2521
proxyOpts.auth = options.proxyUser + ':' + options.proxyPass;
2622
}
23+
} else if (process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy) {
24+
proxyOpts = urlParse.parse(process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy);
2725
}
2826
return proxyOpts
2927
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/node-tunnel",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Nodejs bindings for LambdaTest Tunnel",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)