-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-4834): ensure that MessageStream is destroyed when connections are destroyed #3482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(NODE-4834): ensure that MessageStream is destroyed when connections are destroyed #3482
Conversation
…estroyed flags and on{Error,Timeout,Close} event handlers
durran
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our testing standards (and being in line with spec language) - "should" in the test description would not be used when something "must" be true. Sorry @W-A-James - we should have updated you when you came back. :)
…and terminology used in spec Co-authored-by: Durran Jordan <[email protected]>
…r than explicit values
3b59a12
nbbeeken
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nearly lgtm to.not.have.been.calledOnce cleanups
dariakp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@W-A-James can you also include the other two destroy() cases in the force true/false blocks? because currently you use force: false in both of them, and it's relevant to know what happens in both cases. More precisely, you could take this case:
ends the tcp socket and destroys the messageStream and make it a separate ends the tcp socket it block under each true/false block, and then take calls stream.end exactly once when destroy is called multiple times and move it under false, then make an analogous case under true
b5c6876 to
878c764
Compare
dariakp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on the tests, thanks!
…tions_are_destroyed
…onnections are destroyed (mongodb#3482)" This reverts commit 8338bae.
…ns are destroyed (#3482)
…ns are destroyed (#3482)
<p>This PR was automatically created by Snyk using the credentials of a
real user.</p><br /><h3>Snyk has created this PR to upgrade mongodb from
4.13.0 to 4.14.0.</h3>
:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.
<hr/>
- The recommended version is **1 version** ahead of your current
version.
- The recommended version was released **2 months ago**, on 2023-02-07.
<details>
<summary><b>Release notes</b></summary>
<br/>
<details>
<summary>Package name: <b>mongodb</b></summary>
<ul>
<li>
<b>4.14.0</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.14.0">2023-02-07</a></br><p>The
MongoDB Node.js team is pleased to announce version 4.14.0 of the
mongodb package!</p>
<h3>Deprecations</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4992">NODE-4992</a>:</strong>
Deprecate methods and options that reference legacy logger (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3532"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3532/hovercard">#3532</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6c94b4a826f51796a23d26f0d1976e5dfcd88d88">6c94b4a</a>)</li>
</ul>
<h3>Bug Fixes</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4999">NODE-4999</a>:</strong>
Write Concern 0 Must Not Affect Read Operations (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3541"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3541/hovercard">#3541</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/ddfc2b9bc0475b3d18db355ed73cebfccaf6b874">ddfc2b9</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-5026">NODE-5026</a>:</strong>
revert "ensure that MessageStream is destroyed when connections are
destroyed" (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3551"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3551/hovercard">#3551</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/c4da623b1b30439521ce59e4d9db810ea7d213e2">c4da623</a>)</li>
</ul>
<h2>Documentation</h2>
<ul>
<li>Reference: <a href="https://docs.mongodb.com/drivers/node/current/"
rel="nofollow">https://docs.mongodb.com/drivers/node/current/</a></li>
<li>API: <a href="https://mongodb.github.io/node-mongodb-native/4.14/"
rel="nofollow">https://mongodb.github.io/node-mongodb-native/4.14/</a></li>
<li>Changelog: <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/blob/v4.14.0/HISTORY.md">HISTORY.md</a></li>
</ul>
<p>We invite you to try the mongodb library immediately, and report any
issues to the <a href="https://jira.mongodb.org/projects/NODE"
rel="nofollow">NODE project</a>.</p>
</li>
<li>
<b>4.13.0</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.13.0">2022-12-19</a></br><p>The
MongoDB Node.js team is pleased to announce version 4.13.0 of the
mongodb package!</p>
<h3>Features</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4691">NODE-4691</a>:</strong>
interrupt in-flight operations on heartbeat failure (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3457"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3457/hovercard">#3457</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/e641bd44ef39d64b8b572e7a8ab6bfc71a2b4bed">e641bd4</a>)</li>
</ul>
<h3>Bug Fixes</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4447">NODE-4447</a>:</strong>
disable causal consistency in implicit sessions (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3479"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3479/hovercard">#3479</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6566fb58400c956bb5e56bd7c8affe2ebf2ce558">6566fb5</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4834">NODE-4834</a>:</strong>
ensure that MessageStream is destroyed when connections are destroyed
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3482"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3482/hovercard">#3482</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/8338bae933c777dee4e7e49dbcf52c4fd7047528">8338bae</a>)</li>
</ul>
<h2>Documentation</h2>
<ul>
<li>Reference: <a href="https://docs.mongodb.com/drivers/node/current/"
rel="nofollow">https://docs.mongodb.com/drivers/node/current/</a></li>
<li>API: <a href="https://mongodb.github.io/node-mongodb-native/4.13/"
rel="nofollow">https://mongodb.github.io/node-mongodb-native/4.13/</a></li>
<li>Changelog: <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/blob/main/HISTORY.md">HISTORY.md</a></li>
</ul>
<p>We invite you to try the mongodb driver immediately, and report any
issues to the <a href="https://jira.mongodb.org/projects/NODE"
rel="nofollow">NODE project</a>.</p>
</li>
</ul>
from <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases">mongodb
GitHub release notes</a>
</details>
</details>
<details>
<summary><b>Commit messages</b></summary>
</br>
<details>
<summary>Package name: <b>mongodb</b></summary>
<ul>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/908b3b6b7aad13a411439624431382aeca8ab6cd">908b3b6</a>
chore(release): 4.14.0</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/c4da623b1b30439521ce59e4d9db810ea7d213e2">c4da623</a>
fix(NODE-5026): revert "ensure that MessageStream is destroyed when
connections are destroyed" (#3551)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6a906fc3c7e657dd4bc9e04a895b53df605ace0d">6a906fc</a>
ci(NODE-5012): break apart mongosh integration tests (#3546)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/b1fc872fcc9d986f034c72e91f11622fcf85fb6b">b1fc872</a>
test(NODE-5015): clientEncryption createEncryptedCollection helper
(#3555)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/ddfc2b9bc0475b3d18db355ed73cebfccaf6b874">ddfc2b9</a>
fix(NODE-4999): Write Concern 0 Must Not Affect Read Operations
(#3541)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/ed6c957a064c6a09ffe3a6b68c445839ba5904fb">ed6c957</a>
test(NODE-4974): backport range index tests to 4x (#3539)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6c94b4a826f51796a23d26f0d1976e5dfcd88d88">6c94b4a</a>
feat(NODE-4992): Deprecate methods and options that reference legacy
logger (#3532)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/4c49b2e03b77a7c2f878207c6953d3531cecabe4">4c49b2e</a>
ci: pull in misc CI fixes for the 4x branch (#3536)</li>
</ul>
<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/compare/eb5f651f4f278ae1437a0df0b84e9a8529cbabc7...908b3b6b7aad13a411439624431382aeca8ab6cd">Compare</a>
</details>
</details>
<hr/>
**Note:** *You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs.*
For more information: <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiIzM2JjNWJhNS0xMjBkLTQ3NzUtOTY2OS02NmFkMzgwZTk0ZjYiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjMzYmM1YmE1LTEyMGQtNDc3NS05NjY5LTY2YWQzODBlOTRmNiJ9fQ=="
width="0" height="0"/>
🧐 [View latest project
report](https://app.snyk.io/org/say383/project/063a08f4-06ac-4efa-a1ca-f6fa23cf21b4?utm_source=github&utm_medium=referral&page=upgrade-pr)
🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/say383/project/063a08f4-06ac-4efa-a1ca-f6fa23cf21b4/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr)
🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/say383/project/063a08f4-06ac-4efa-a1ca-f6fa23cf21b4/settings/integration?pkg=mongodb&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades)
<!---
(snyk:metadata:{"prId":"33bc5ba5-120d-4775-9669-66ad380e94f6","prPublicId":"33bc5ba5-120d-4775-9669-66ad380e94f6","dependencies":[{"name":"mongodb","from":"4.13.0","to":"4.14.0"}],"packageManager":"npm","type":"auto","projectUrl":"https://app.snyk.io/org/say383/project/063a08f4-06ac-4efa-a1ca-f6fa23cf21b4?utm_source=github&utm_medium=referral&page=upgrade-pr","projectPublicId":"063a08f4-06ac-4efa-a1ca-f6fa23cf21b4","env":"prod","prType":"upgrade","vulns":[],"issuesToFix":[],"upgrade":[],"upgradeInfo":{"versionsDiff":1,"publishedDate":"2023-02-07T18:17:08.029Z"},"templateVariants":[],"hasFixes":false,"isMajorUpgrade":false,"isBreakingChange":false,"priorityScoreList":[]})
--->
<h3>Snyk has created this PR to upgrade mongodb from 4.10.0 to
4.14.0.</h3>
:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.
<hr/>
- The recommended version is **5 versions** ahead of your current
version.
- The recommended version was released **2 months ago**, on 2023-02-07.
<details>
<summary><b>Release notes</b></summary>
<br/>
<details>
<summary>Package name: <b>mongodb</b></summary>
<ul>
<li>
<b>4.14.0</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.14.0">2023-02-07</a></br><p>The
MongoDB Node.js team is pleased to announce version 4.14.0 of the
mongodb package!</p>
<h3>Deprecations</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4992">NODE-4992</a>:</strong>
Deprecate methods and options that reference legacy logger (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3532"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3532/hovercard">#3532</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6c94b4a826f51796a23d26f0d1976e5dfcd88d88">6c94b4a</a>)</li>
</ul>
<h3>Bug Fixes</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4999">NODE-4999</a>:</strong>
Write Concern 0 Must Not Affect Read Operations (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3541"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3541/hovercard">#3541</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/ddfc2b9bc0475b3d18db355ed73cebfccaf6b874">ddfc2b9</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-5026">NODE-5026</a>:</strong>
revert "ensure that MessageStream is destroyed when connections are
destroyed" (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3551"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3551/hovercard">#3551</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/c4da623b1b30439521ce59e4d9db810ea7d213e2">c4da623</a>)</li>
</ul>
<h2>Documentation</h2>
<ul>
<li>Reference: <a href="https://docs.mongodb.com/drivers/node/current/"
rel="nofollow">https://docs.mongodb.com/drivers/node/current/</a></li>
<li>API: <a href="https://mongodb.github.io/node-mongodb-native/4.14/"
rel="nofollow">https://mongodb.github.io/node-mongodb-native/4.14/</a></li>
<li>Changelog: <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/blob/v4.14.0/HISTORY.md">HISTORY.md</a></li>
</ul>
<p>We invite you to try the mongodb library immediately, and report any
issues to the <a href="https://jira.mongodb.org/projects/NODE"
rel="nofollow">NODE project</a>.</p>
</li>
<li>
<b>4.13.0</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.13.0">2022-12-19</a></br><p>The
MongoDB Node.js team is pleased to announce version 4.13.0 of the
mongodb package!</p>
<h3>Features</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4691">NODE-4691</a>:</strong>
interrupt in-flight operations on heartbeat failure (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3457"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3457/hovercard">#3457</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/e641bd44ef39d64b8b572e7a8ab6bfc71a2b4bed">e641bd4</a>)</li>
</ul>
<h3>Bug Fixes</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4447">NODE-4447</a>:</strong>
disable causal consistency in implicit sessions (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3479"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3479/hovercard">#3479</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6566fb58400c956bb5e56bd7c8affe2ebf2ce558">6566fb5</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4834">NODE-4834</a>:</strong>
ensure that MessageStream is destroyed when connections are destroyed
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3482"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3482/hovercard">#3482</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/8338bae933c777dee4e7e49dbcf52c4fd7047528">8338bae</a>)</li>
</ul>
<h2>Documentation</h2>
<ul>
<li>Reference: <a href="https://docs.mongodb.com/drivers/node/current/"
rel="nofollow">https://docs.mongodb.com/drivers/node/current/</a></li>
<li>API: <a href="https://mongodb.github.io/node-mongodb-native/4.13/"
rel="nofollow">https://mongodb.github.io/node-mongodb-native/4.13/</a></li>
<li>Changelog: <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/blob/main/HISTORY.md">HISTORY.md</a></li>
</ul>
<p>We invite you to try the mongodb driver immediately, and report any
issues to the <a href="https://jira.mongodb.org/projects/NODE"
rel="nofollow">NODE project</a>.</p>
</li>
<li>
<b>4.12.1</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.12.1">2022-11-23</a></br><p>The
MongoDB Node.js team is pleased to announce version 4.12.1 of the
mongodb package!</p>
<h2>Release Highlights</h2>
<p>This version includes a fix to a regression in our monitoring logic
that could cause process crashing errors that was introduced in
v4.12.0.</p>
<p>If you are using v4.12.0 of the Node driver, we strongly encourage
you to upgrade.</p>
<h3>Bug Fixes</h3>
<ul>
<li><strong><a href="https://jira.mongodb.org/browse/NODE-4830"
rel="nofollow">NODE-4830</a>:</strong> lazily import aws module (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3476"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3476/hovercard">#3476</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/ff375e9cfb84c85b7036a7ef0f87385d3ec126bb">ff375e9</a>)</li>
<li><strong><a href="https://jira.mongodb.org/browse/NODE-4831"
rel="nofollow">NODE-4831</a>:</strong> check map value is not undefined
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3477"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3477/hovercard">#3477</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/9795cdb19f8e652b4dc4badd4fe8e6d1a7b837a6">9795cdb</a>)</li>
</ul>
<h2>Documentation</h2>
<ul>
<li><a href="https://docs.mongodb.com/drivers/node/current/"
rel="nofollow">Reference</a></li>
<li><a href="https://mongodb.github.io/node-mongodb-native/4.12"
rel="nofollow">API</a></li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/blob/main/HISTORY.md">Changelog</a></li>
</ul>
<p>We invite you to try the <code>mongodb</code> library immediately,
and report any issues to the <a
href="https://jira.mongodb.org/projects/NODE" rel="nofollow">NODE
project</a>.</p>
</li>
<li>
<b>4.12.0</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.12.0">2022-11-16</a></br><p>The
MongoDB Node.js team is pleased to announce version 4.12.0 of the
mongodb package!</p>
<h2>Release Highlights</h2>
<h3>ChangeStreams are now AsyncIterators</h3>
<p>ChangeStreams are now async iterables and can be used anywhere that
expects an async iterable. Notably, change streams can now be used in
Javascript for-await loops:</p>
<div class="highlight highlight-source-ts notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="const changeStream =
collection.watch();
for await (const change of changeStream) {
console.log(“Received change: “, change);
}"><pre><span class="pl-k">const</span> <span
class="pl-s1">changeStream</span> <span class="pl-c1">=</span> <span
class="pl-s1">collection</span><span class="pl-kos">.</span><span
class="pl-en">watch</span><span class="pl-kos">(</span><span
class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">for</span> <span class="pl-k">await</span> <span
class="pl-kos">(</span><span class="pl-k">const</span> <span
class="pl-s1">change</span> <span class="pl-k">of</span> <span
class="pl-s1">changeStream</span><span class="pl-kos">)</span> <span
class="pl-kos">{</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span
class="pl-en">log</span><span class="pl-kos">(</span><span
class="pl-s1">“Received</span> <span class="pl-s1">change</span>: <span
class="pl-s1">“</span><span class="pl-kos">,</span> <span
class="pl-s1">change</span><span class="pl-kos">)</span><span
class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p>Some users may have been using change streams in for-await loops
manually by using a for-await loop with the ChangeStream’s internal
cursor. For example:</p>
<div class="highlight highlight-source-ts notranslate position-relative
overflow-auto" data-snippet-clipboard-copy-content="const changeStream =
collection.watch();
for await (const change of changeStream.cursor) {
console.log(“Received change: “, change);
}"><pre><span class="pl-k">const</span> <span
class="pl-s1">changeStream</span> <span class="pl-c1">=</span> <span
class="pl-s1">collection</span><span class="pl-kos">.</span><span
class="pl-en">watch</span><span class="pl-kos">(</span><span
class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">for</span> <span class="pl-k">await</span> <span
class="pl-kos">(</span><span class="pl-k">const</span> <span
class="pl-s1">change</span> <span class="pl-k">of</span> <span
class="pl-s1">changeStream</span><span class="pl-kos">.</span><span
class="pl-c1">cursor</span><span class="pl-kos">)</span> <span
class="pl-kos">{</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span
class="pl-en">log</span><span class="pl-kos">(</span><span
class="pl-s1">“Received</span> <span class="pl-s1">change</span>: <span
class="pl-s1">“</span><span class="pl-kos">,</span> <span
class="pl-s1">change</span><span class="pl-kos">)</span><span
class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p>The change stream cursor has no support for resumabilty and
consequently the change stream will never attempt to resume on any
errors. We <strong>strongly caution</strong> against using a change
stream cursor as an async iterable and <strong>strongly
recommend</strong> using the change stream directly.</p>
<h3>Server Monitoring Fix When Monitoring Events are Skipped</h3>
<p>Version 4.7.0 of the Node driver released an improvement to our
server monitoring in FAAS environments by allowing the driver to skip
monitoring events if there were more than one monitoring events in the
queue when the monitoring code restarted. When skipping monitoring
events that contained a topology change, the driver would incorrectly
fail to update its view of the topology.</p>
<p>Version 4.12.0 fixes this issue by ensuring that the topology is
always updated when monitoring events are processed.</p>
<h3>Performance Improvements with Buffering</h3>
<p>This release also modifies the data structures used internally in the
driver to use linked lists in places where random access is not required
and constant time insertion and deletion is beneficial.</p>
<h2>External Contributions</h2>
<p>Many thanks to <a class="user-mention notranslate"
data-hovercard-type="user" data-hovercard-url="/users/ImRodry/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://snyk.io/redirect/github/ImRodry">@ ImRodry</a> for helping
us fix the documentation for our deprecated callback overloads in this
release!</p>
<h3>Features</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4683">NODE-4683</a>:</strong>
make ChangeStream an async iterable (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3454"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3454/hovercard">#3454</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/df8d9a4f2bb68f747ecb2b4d88a9137ca4f6ecb4">df8d9a4</a>)</li>
</ul>
<h3>Deprecations</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4681">NODE-4681</a>:</strong>
deprecate modify result (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3459"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3459/hovercard">#3459</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6a8776c32c8c63beb7871458413baadd9e126efa">6a8776c</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4733">NODE-4733</a>:</strong>
deprecate result and getLastOp (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3458"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3458/hovercard">#3458</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/a143d3bc6768076fe65368feac0726ca201d4bb0">a143d3b</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4757">NODE-4757</a>:</strong>
deprecate unused PipeOptions (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3466"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3466/hovercard">#3466</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/1a5e619f13c3112d75f7b40d2e2cbde027de7f0b">1a5e619</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4809">NODE-4809</a>:</strong>
deprecate the existing logger (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3464"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3464/hovercard">#3464</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/1eea4f0f5821bb44c86f653d5a3a6c022a5cf55b">1eea4f0</a>)</li>
</ul>
<h3>Bug Fixes</h3>
<ul>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4609">NODE-4609</a>:</strong>
allow mapping to falsey non-null values in cursors (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3452"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3452/hovercard">#3452</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/1bf6ef1792deb108f3fc58429b165e9bdd06b4a7">1bf6ef1</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4735">NODE-4735</a>:</strong>
fix change stream consecutive resumabilty (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3453"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3453/hovercard">#3453</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/89b27e93e5416fb74ec716f3dc541c104c3a90ce">89b27e9</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4753">NODE-4753</a>:</strong>
remove erroneous deprecation of geoNear (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3465"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3465/hovercard">#3465</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/199dcaf7b462b1c488544cbdbaecaad0417c62d7">199dcaf</a>)</li>
<li><strong><a class="issue-link js-issue-link notranslate"
rel="noopener noreferrer nofollow"
href="https://jira.mongodb.org/browse/NODE-4783">NODE-4783</a>:</strong>
handle orphaned operation descriptions (<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/issues/3463"
data-hovercard-type="pull_request"
data-hovercard-url="/mongodb/node-mongodb-native/pull/3463/hovercard">#3463</a>)
(<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/4c9b4d846e5ba6e86d0d0592ff8bf76654d0fa51">4c9b4d8</a>)</li>
</ul>
<h2>Documentation</h2>
<ul>
<li><a href="https://docs.mongodb.com/drivers/node/current/"
rel="nofollow">Reference</a></li>
<li><a href="https://mongodb.github.io/node-mongodb-native/4.12"
rel="nofollow">API</a></li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/blob/main/HISTORY.md">Changelog</a></li>
</ul>
<p>We invite you to try the <code>mongodb</code> library immediately,
and report any issues to the <a
href="https://jira.mongodb.org/projects/NODE" rel="nofollow">NODE
project</a>.</p>
</li>
<li>
<b>4.11.0</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.11.0">2022-10-19</a></br><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.11.0">
Read more </a>
</li>
<li>
<b>4.10.0</b> - <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.10.0">2022-09-19</a></br><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases/tag/v4.10.0">
Read more </a>
</li>
</ul>
from <a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/releases">mongodb
GitHub release notes</a>
</details>
</details>
<details>
<summary><b>Commit messages</b></summary>
</br>
<details>
<summary>Package name: <b>mongodb</b></summary>
<ul>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/908b3b6b7aad13a411439624431382aeca8ab6cd">908b3b6</a>
chore(release): 4.14.0</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/c4da623b1b30439521ce59e4d9db810ea7d213e2">c4da623</a>
fix(NODE-5026): revert "ensure that MessageStream is destroyed when
connections are destroyed" (#3551)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6a906fc3c7e657dd4bc9e04a895b53df605ace0d">6a906fc</a>
ci(NODE-5012): break apart mongosh integration tests (#3546)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/b1fc872fcc9d986f034c72e91f11622fcf85fb6b">b1fc872</a>
test(NODE-5015): clientEncryption createEncryptedCollection helper
(#3555)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/ddfc2b9bc0475b3d18db355ed73cebfccaf6b874">ddfc2b9</a>
fix(NODE-4999): Write Concern 0 Must Not Affect Read Operations
(#3541)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/ed6c957a064c6a09ffe3a6b68c445839ba5904fb">ed6c957</a>
test(NODE-4974): backport range index tests to 4x (#3539)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6c94b4a826f51796a23d26f0d1976e5dfcd88d88">6c94b4a</a>
feat(NODE-4992): Deprecate methods and options that reference legacy
logger (#3532)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/4c49b2e03b77a7c2f878207c6953d3531cecabe4">4c49b2e</a>
ci: pull in misc CI fixes for the 4x branch (#3536)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/eb5f651f4f278ae1437a0df0b84e9a8529cbabc7">eb5f651</a>
chore(release): 4.13.0</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/5d9711b6c93bc77c3e6aaa3a15bceb2954d03ad2">5d9711b</a>
docs: generate docs from latest main (#3471)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/8338bae933c777dee4e7e49dbcf52c4fd7047528">8338bae</a>
fix(NODE-4834): ensure that MessageStream is destroyed when connections
are destroyed (#3482)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/9f945c4f361f65552624b2de61405cd48c061e9a">9f945c4</a>
test(NODE-4800): update build env scripts (#3487)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6ef11d70c07e2e223d376e7527354ddf758a163a">6ef11d7</a>
feat(NODE-4810): define the new Logger (#3475)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/dfcc3d9d4ff576cf427ef5cd5b5b1cf3266c70c7">dfcc3d9</a>
test(NODE-4826): update command monitoring tests (#3488)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/d56414f3c0991ca9370e20ab9ef1ce99fde0072d">d56414f</a>
test(NODE-4498): ts tests for OptionalId wrapping schemas with _id
(#3486)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/e3ead5835cc64d19fae97854bf535c95d6af571e">e3ead58</a>
ci(NODE-4872): add permissions to dependency check workflow (#3483)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/fb22f23e651744658a0ba3057ab49b1532441ff2">fb22f23</a>
chore: update PR template commit message example (#3484)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/6566fb58400c956bb5e56bd7c8affe2ebf2ce558">6566fb5</a>
fix(NODE-4447): disable causal consistency in implicit sessions
(#3479)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/bb6683dcc4da3dbc5fde78b95dc555130ead126e">bb6683d</a>
ci(NODE-4856): break apart ts tests into separate tasks and skip failing
tasks on typescript next (#3474)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/a57cd6431b64f2cd45e220591be4271a8c572011">a57cd64</a>
chore(no-story): allow clones that use https in docs pre-generation
check (#3481)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/57b98e06ebfa263685ddafd87d168f56081d10d9">57b98e0</a>
ci(NODE-4842): add latest Node version to CI (#3478)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/9a3055a61f03abd87e5d62311592d4ff04edefdb">9a3055a</a>
chore(no-story): add debug info to docs generation (#3480)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/e641bd44ef39d64b8b572e7a8ab6bfc71a2b4bed">e641bd4</a>
feat(NODE-4691): interrupt in-flight operations on heartbeat failure
(#3457)</li>
<li><a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/commit/73e92ce93e54b8d4d966ede319c3d7805ced6776">73e92ce</a>
chore(release): 4.12.1</li>
</ul>
<a
href="https://snyk.io/redirect/github/mongodb/node-mongodb-native/compare/dc34388ba910304c24e24dcaef36a6e5f9f54e2f...908b3b6b7aad13a411439624431382aeca8ab6cd">Compare</a>
</details>
</details>
<hr/>
**Note:** *You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs.*
For more information: <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiJjYzMxYmI1Mi1hMTEwLTQ5NGMtYWUzYS1mYWE5M2QyNTA3YzEiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6ImNjMzFiYjUyLWExMTAtNDk0Yy1hZTNhLWZhYTkzZDI1MDdjMSJ9fQ=="
width="0" height="0"/>
🧐 [View latest project
report](https://app.snyk.io/org/satt/project/b89486be-ad07-4d6c-a51a-2fa8a25baa00?utm_source=github&utm_medium=referral&page=upgrade-pr)
🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/satt/project/b89486be-ad07-4d6c-a51a-2fa8a25baa00/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr)
🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/satt/project/b89486be-ad07-4d6c-a51a-2fa8a25baa00/settings/integration?pkg=mongodb&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades)
<!---
(snyk:metadata:{"prId":"cc31bb52-a110-494c-ae3a-faa93d2507c1","prPublicId":"cc31bb52-a110-494c-ae3a-faa93d2507c1","dependencies":[{"name":"mongodb","from":"4.10.0","to":"4.14.0"}],"packageManager":"npm","type":"auto","projectUrl":"https://app.snyk.io/org/satt/project/b89486be-ad07-4d6c-a51a-2fa8a25baa00?utm_source=github&utm_medium=referral&page=upgrade-pr","projectPublicId":"b89486be-ad07-4d6c-a51a-2fa8a25baa00","env":"prod","prType":"upgrade","vulns":[],"issuesToFix":[],"upgrade":[],"upgradeInfo":{"versionsDiff":5,"publishedDate":"2023-02-07T18:17:08.029Z"},"templateVariants":[],"hasFixes":false,"isMajorUpgrade":false,"isBreakingChange":false,"priorityScoreList":[]})
--->
Description
What is changing?
Adding logic to ensure that a
Connection'sMessageStreamis always destroyed when the associated TCP socket is destroyed. Also added guard logic to ensure thatonTimeout,onClose, andonErrorare nops if theConnectionhas already been destroyed.Inline documentation was added to differentiate the
closedanddestroyedflags and to explain the conditions under which theonTimeout,onClose, andonErrorevent handlers are called.Is there new documentation needed for these changes?
No
What is the motivation for this change?
Prior to this change, a
Connection'sMessageStreamwas not destroyed when theConnectionwas destroyed, which could lead to memory leaks.Double check the following
npm run check:lintscript<type>(NODE-xxxx)<!>: <description>