awslabs / aws-embedded-metrics-node

Amazon CloudWatch Embedded Metric Format Client Library
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html
Apache License 2.0
252 stars 35 forks source link

fix tcp socket stream destruction #126

Closed markkuhn closed 2 years ago

markkuhn commented 2 years ago

Issue #, if available: #120

Description of changes:

Changes made to how the socket initially connects to its endpoint.

As per Nodejs documentation, "[socket.connect()] should only be used for reconnecting a socket after 'close' has been emitted or otherwise it may lead to undefined behavior". The previous version was at times calling socket.connect() without the close event being emitted. This would sometimes try to connect to a socket that is already connected (EISCONN) and would destroy the stream. Additionally, the writable property in net.Socket() was removed since it was causing socket streams on node >=v15.3.0 to start as readOnly and with an additional connect() attempt would lead to undefined behaviour.

To avoid the same issues pre 0034ce1cd5e7109a43f3a1551a985ffa984247ce, an async init() method within the constructor was added to initialize the connection once a TCP Socket is created.

Additionally, fixed critical, high and moderate severity dependency related security alerts: #124, CVE-2021-43138, CVE-2021-3807, CVE-2021-3918, CVE-2021-44906, CVE-2021-3777, CVE-2021-23343, CVE-2020-28469

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

markkuhn commented 2 years ago

Initial build failed due to outdated CodeBuild environment image.