-
Notifications
You must be signed in to change notification settings - Fork 439
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: skip config validation when using connector #1542
base: master
Are you sure you want to change the base?
feat: skip config validation when using connector #1542
Conversation
e86efcc
to
8c62e1d
Compare
Codecov Report
@@ Coverage Diff @@
## master #1542 +/- ##
==========================================
- Coverage 80.45% 79.96% -0.50%
==========================================
Files 92 92
Lines 4692 4682 -10
Branches 871 866 -5
==========================================
- Hits 3775 3744 -31
- Misses 644 672 +28
+ Partials 273 266 -7
|
@@ -1902,6 +1902,9 @@ class Connection extends EventEmitter { | |||
|
|||
if (this.config.options.port) { | |||
return this.connectOnPort(this.config.options.port, this.config.options.multiSubnetFailover, signal, this.config.options.connector); | |||
} else if (this.config.options.connector) { | |||
// port and multiSubnetFailover are not used when using a custom connector | |||
return this.connectOnPort(0, false, signal, this.config.options.connector); |
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.
There is a possibility that user proved both port and connector from config, the logic will go into the if statement instead of the else if and still work properly since the connector is passed into connectOnPort. Another case is, if use only pass in connector and logic will got into the else if and still call the connectOnPort.
Under both cases, with or without port passed into connectOnPort function, the connect socket here will be provided by the passed in customConnector, and the passed in port number should be ignored within connectOnPort.
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.
thanks @MichaelSun90! these are also great examples of the kind of tests I can add to make codecov happy 😊
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.
I added the connector check to take precedence just to err on the safe side but at the same time I made sure to set port
to undefined during the validation phase of the constructor along with adding tests for the combinations of providing port/server/connector. Let me know if it looks better now 😊
@ruyadorno I'm wondering how this is going to interact with all the code that expects It would be nice if that all could be cleaned up to either be consistent, or at least not to lead to log messages containing |
@arthurschreiber that's a good point! let me take a look at these I might just try to clean them up as part of this PR then in case it looks actionable 😊 |
2a7fbe5
to
8e92a0b
Compare
@arthurschreiber I updated the PR with a pass at updating occurrences of many logging messages that were using the |
3221920
to
f5960e4
Compare
Went through a few more iterations to improve code coverage and cleaned a few things up, should be good to go now 😊 lmk! |
This changeset fixes a problem in the original custom `connector` factory method implementation that required the `server` config property to be defined even though its value is ignored. Removing the validation when `config.options.connector` is defined fixes the problem. Ref: tediousjs#1540 Fixes: tediousjs#1541 Signed-off-by: Ruy Adorno <[email protected]>
20bf8f1
to
634c947
Compare
hi @MichaelSun90! Added your suggestion to update the type definition for the Let me know if you think this is in a good shape to land now 😊 I'm looking forward to finally have the |
@@ -14,7 +14,7 @@ const MYSTERY_HEADER_LENGTH = 3; | |||
type LookupFunction = (hostname: string, options: dns.LookupAllOptions, callback: (err: NodeJS.ErrnoException | null, addresses: dns.LookupAddress[]) => void) => void; | |||
|
|||
// Most of the functionality has been determined from from jTDS's MSSqlServerInfo class. | |||
export async function instanceLookup(options: { server: string, instanceName: string, timeout?: number, retries?: number, port?: number, lookup?: LookupFunction, signal: AbortSignal }) { | |||
export async function instanceLookup(options: { server: undefined | string, instanceName: string, timeout?: number, retries?: number, port?: number, lookup?: LookupFunction, signal: AbortSignal }) { |
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.
@ruyadorno I think this change is not correct. Logically, the instanceLookup
can not work without a hostname, so changing the type to allow undefined
is not correct. Also, casting options.server
to a string using String
further down is also not right - if someone would call this method with undefined
, it would try to send udp messages to the hostname "undefined"
. 😅
I think it's better to change the location where this method is called instead (will leave a separate comment for that).
if (this.config.options.connector) { | ||
// port and multiSubnetFailover are not used when using a custom connector | ||
return this.connectOnPort(0, false, signal, this.config.options.connector); | ||
} else if (this.config.options.port) { | ||
return this.connectOnPort(this.config.options.port, this.config.options.multiSubnetFailover, signal, this.config.options.connector); | ||
} else { | ||
return instanceLookup({ |
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.
I think this is the place you need to change. We know here that this.config.server
is not undefined
in this else
block (even if the type is declared as string | undefined
), so we can tell TypeScript that this is the case by changing this.config.server
to this.config.server!
.
This changeset fixes a problem in the original custom
connector
factory method implementation that required theserver
config property to be defined even though its value is ignored.Removing the validation when
config.options.connector
is defined fixes the problem.Ref: #1540
Fixes: #1541