aws-embedded-metrics
Advanced tools
Comparing version
@@ -50,2 +50,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// ensure the socket is open and writable | ||
yield this.waitForOpenConnection(); | ||
@@ -57,3 +58,3 @@ yield new Promise((resolve, reject) => { | ||
}; | ||
const wasFlushedToKernel = this.socket.once('error', onSendError).write(message, (err) => { | ||
const wasFlushedToKernel = this.socket.write(message, (err) => { | ||
if (!err) { | ||
@@ -75,2 +76,3 @@ Logger_1.LOG('Write succeeded'); | ||
Logger_1.LOG('TcpClient disconnected due to:', eventName); | ||
this.socket.removeAllListeners(); | ||
this.socket.destroy(); | ||
@@ -81,3 +83,3 @@ this.socket.unref(); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.socket.writable) { | ||
if (!this.socket.writeable || this.socket.readyState !== 'open') { | ||
yield this.establishConnection(); | ||
@@ -90,12 +92,34 @@ } | ||
yield new Promise((resolve, reject) => { | ||
this.socket | ||
.connect(this.endpoint.port, this.endpoint.host, () => { | ||
const onError = (e) => { | ||
// socket is already open, no need to connect | ||
if (e.message.includes('EISCONN')) { | ||
resolve(); | ||
return; | ||
} | ||
Logger_1.LOG('TCP Client received error', e); | ||
this.disconnect(e.message); | ||
reject(e); | ||
}; | ||
const onConnect = () => { | ||
this.socket.removeListener('error', onError); | ||
Logger_1.LOG('TcpClient connected.', this.endpoint); | ||
resolve(); | ||
}) | ||
.once('error', e => { | ||
this.disconnect('error'); | ||
this.socket.removeListener('connection', resolve); | ||
reject(e); | ||
}); | ||
}; | ||
// TODO: convert this to a proper state machine | ||
switch (this.socket.readyState) { | ||
case 'open': | ||
resolve(); | ||
break; | ||
case 'opening': | ||
// the socket is currently opening, we will resolve | ||
// or fail the current promise on the connect or | ||
// error events | ||
this.socket.once('connect', onConnect); | ||
this.socket.once('error', onError); | ||
break; | ||
default: | ||
Logger_1.LOG('opening connection with socket in state: ', this.socket.readyState); | ||
this.socket.connect(this.endpoint.port, this.endpoint.host, onConnect).once('error', onError); | ||
break; | ||
} | ||
}); | ||
@@ -102,0 +126,0 @@ }); |
{ | ||
"name": "aws-embedded-metrics", | ||
"version": "1.1.0", | ||
"version": "1.1.1-alpha4", | ||
"description": "AWS Embedded Metrics Client Library", | ||
@@ -15,3 +15,3 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "jest --config jestconfig.json", | ||
"test": "jest --runInBand --detectOpenHandles --config jestconfig.json", | ||
"integ": "./bin/run-integ-tests.sh", | ||
@@ -18,0 +18,0 @@ "exec-integ": "jest --config jestconfig.integ.json", |
@@ -14,2 +14,3 @@ # aws-embedded-metrics | ||
* [Examples](#examples) | ||
* [Testing Examples](#testing-examples) | ||
* [Development](#development) | ||
@@ -323,2 +324,6 @@ | ||
## Testing Examples | ||
Check out the [unit test examples](https://github.com/awslabs/aws-embedded-metrics-node/tree/master/examples/testing) directory to get started. Here we provide a few examples to help you write tests against code that depends on this package. | ||
## Development | ||
@@ -325,0 +330,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
377
1.34%13
-23.53%103541
-9.67%66
-10.81%2012
-11.95%2
100%