🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

aws-embedded-metrics

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-embedded-metrics - npm Package Compare versions

Comparing version

to
1.1.1-alpha4

44

lib/sinks/connections/TcpClient.js

@@ -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 @@