-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-6864): socket errors are not always converted to MongoNetworkErrors #4473
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
da58b09
fix(NODE-6864): socket errors are not always converted to MongoNetwor…
nbbeeken 7b0caf9
chore: fix less promises left over on windows
nbbeeken 60a8c66
test: network error wrapping
nbbeeken 2283c38
chore: remove tests
nbbeeken 901f878
test: remove lower bound
nbbeeken df146f5
Merge branch 'main' into NODE-6858-errors
baileympearson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
test/integration/node-specific/convert_socket_errors.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Duplex } from 'node:stream'; | ||
|
||
import { expect } from 'chai'; | ||
import * as sinon from 'sinon'; | ||
|
||
import { Connection, type MongoClient, MongoNetworkError, ns } from '../../mongodb'; | ||
import { clearFailPoint, configureFailPoint } from '../../tools/utils'; | ||
|
||
describe('Socket Errors', () => { | ||
describe('when a socket emits an error', () => { | ||
it('command throws a MongoNetworkError', async () => { | ||
const socket = new Duplex(); | ||
// @ts-expect-error: not a real socket | ||
const connection = new Connection(socket, {}); | ||
const testError = new Error('blah'); | ||
socket.emit('error', testError); | ||
const commandRes = connection.command(ns('a.b'), { ping: 1 }, {}); | ||
|
||
const error = await commandRes.catch(error => error); | ||
expect(error).to.be.instanceOf(MongoNetworkError); | ||
expect(error.cause).to.equal(testError); | ||
}); | ||
}); | ||
|
||
describe('when the sized message stream emits an error', () => { | ||
it('command throws the same error', async () => { | ||
const socket = new Duplex(); | ||
// @ts-expect-error: not a real socket | ||
const connection = new Connection(socket, {}); | ||
const testError = new Error('blah'); | ||
// @ts-expect-error: private field | ||
connection.messageStream.emit('error', testError); | ||
const commandRes = connection.command(ns('a.b'), { ping: 1 }, {}); | ||
|
||
const error = await commandRes.catch(error => error); | ||
expect(error).to.equal(testError); | ||
}); | ||
}); | ||
|
||
describe('when destroyed by failpoint', () => { | ||
let client: MongoClient; | ||
let collection; | ||
|
||
const metadata: MongoDBMetadataUI = { requires: { mongodb: '>=4.4' } }; | ||
|
||
beforeEach(async function () { | ||
if (!this.configuration.filters.NodeVersionFilter.filter({ metadata })) { | ||
return; | ||
} | ||
|
||
await configureFailPoint(this.configuration, { | ||
configureFailPoint: 'failCommand', | ||
mode: 'alwaysOn', | ||
data: { | ||
appName: 'failInserts2', | ||
failCommands: ['insert'], | ||
closeConnection: true | ||
} | ||
}); | ||
|
||
client = this.configuration.newClient({}, { appName: 'failInserts2' }); | ||
await client.connect(); | ||
const db = client.db('closeConn'); | ||
collection = db.collection('closeConn'); | ||
}); | ||
|
||
afterEach(async function () { | ||
sinon.restore(); | ||
await clearFailPoint(this.configuration); | ||
await client.close(); | ||
}); | ||
|
||
it('throws a MongoNetworkError', metadata, async () => { | ||
const error = await collection.insertOne({ name: 'test' }).catch(error => error); | ||
expect(error, error.stack).to.be.instanceOf(MongoNetworkError); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.