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
Port tokenHandler mechanism from go-nats (option createConnection()) #267
Port tokenHandler mechanism from go-nats (option createConnection()) #267
Conversation
The Travis CI seems to be failing on unrelated tests. Is there any way to re-run it? |
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.
We don't use Promises in node-nats. Things that require loading information do so in a synchronous mechanism. If your app needs to update the token, likely this should be some function that periodically updates it so you have it available when connect requires it.
Also |
@aricart: How firm are you on the "no-async" policy? It certainly makes it more difficult to track the token expiry outside of the lib. |
the point is that by the time you get a If you look at the other resolutions (for creds files) they are immediately resolved. The process charged with updating can do so whenever. The only contract is for the file to be current when we need it. |
Also if you are dabbling in Promises or async/await or are looking for more 'modern' javascript, take a look at ts-nats. The contract above would still be true (the limitation is not on client, but that nats servers typically disconnect clients very very quickly if the |
@aricart: I agree that speed is off the essence. I hope you noticed that in my tests I setup very long timeouts for token resolutions (I think I tried as far as just under 1000ms), and the server was fine. Again, in |
@aricart: Simplicity is nice and how can you get simpler than asking for a token when you need it? Of course, other approaches can be used, but none of them would be as lean as that simple pattern. |
@andriy-bulynko I am ok with the asking for the token dynamically, I just don't want you to resolve the token within the When the resolution of the token is out of band with the client the worse that could happen is that your client will get an authentication error. |
@aricart: Also, I'm not hung up on promises or any other "modern" ES6 features. I chose the promise approach because it's an easy-to-use data type available in the version of node that's listed as minimally supported by the library. It offers an easy abstraction for returning a value or an error. I could re-write this using the |
replaced with the sync version |
Fixes: #265
Description
I wasn't sure of the best place to plug this in. This PR introduces the code into
createConnection()
. It might work well there because it wouldn't be "interrupting" an otherwise synchronous flow inside theprocessInbound()
. However, it moves the call to obtain the token a bit further from where it would be used. This solution also assumes that the auth is only ever done on a fresh TCP connection. Is this assumption correct?