Skip to content
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

feat: add databaseMirroringPartner event handler #1671

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nick-w-nick
Copy link
Contributor

This PR is to fix #1669, where the library throws an unhandled exception if it encounters an ENVCHANGE event of type DATABASE_MIRRORING_PARTNER.

This behavior isn't explicitly documented, but there have been a few issues brought up regarding this functionality in the past, and it has been stated that tedious does not plan to support failover partners. While that may be the case, this event being emitted by SQL Server is causing Tedious to crash completely rather than simply ignoring it as you would expect.

The changes in this PR are to create the databaseMirroringPartner event emitter and register the necessary handler methods in the associated token handler classes, to prevent the default behavior of throwing an Unexpected token error.

To clarify, this does not implement mirroring functionality or anything of the sort, it simply updates the default behavior to allow the event to pass through and be ignored, rather than unnecessarily throwing an unhandled exception.

Comment on lines 365 to 366
}

onDatabaseMirroringPartner(token: DatabaseMirroringPartnerEnvChangeToken) {
// Do nothing
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this handler to be right below the onDatabaseChange event handler for better ordering and to keep the event next to all of the other ENVCHANGE events.

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.78%. Comparing base (809227a) to head (f209f0e).

Files with missing lines Patch % Lines
src/token/handler.ts 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (809227a) and HEAD (f209f0e). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (809227a) HEAD (f209f0e)
94 90
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1671      +/-   ##
==========================================
- Coverage   86.05%   78.78%   -7.28%     
==========================================
  Files          90       90              
  Lines        4877     4879       +2     
  Branches      918      918              
==========================================
- Hits         4197     3844     -353     
- Misses        675      737      +62     
- Partials        5      298     +293     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 169 to 172
onDatabaseMirroringPartner(token: DatabaseMirroringPartnerEnvChangeToken) {
this.connection.emit('databaseMirroringPartner', token.newValue);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that the database mirroring partner event is sent by the server when the initial SQL setup query is sent by tedious?

This is... surprising. 🤔

The MS-TDS specification states that:

Type 13 (Database Mirroring) is sent in response to a LOGIN7 message whenever connection is requested to a database that it is being served as primary in real-time log shipping. The ENVCHANGE stream reflects the name of the partner node of the database that is being log shipped.

I'm wondering if there's some other issue in the sequencing of how we handle events and which state the handling happens in. Because based just on the specification, this event should not be send by the server in a response to the initial sql query we send.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arthurschreiber You're actually 100% correct, I mistakenly had added the event emitters in each of them during debugging but hadn't removed them to determine if it was a specific handler or not.

I've removed the unnecessary event handler from the InitialSqlTokenHandler class and verified that the event is still handled correctly.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error connecting to MSSQL database with clustering enabled
2 participants