-
Notifications
You must be signed in to change notification settings - Fork 436
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
Forward socket errors to request callbacks. #330
Conversation
The `Connection#transaction` method should only try to roll back transactions if the connection is still in the `LOGGED_IN` state. If the connection is in any other state, we most likely have already disconnected from the database and don't need to rollback anything.
Hmm, what happens when a socket error is raised when not in the |
Yes, I think that's what happens. You'll get a |
Check the |
Yep, I ended up looking at that, and it cleared things up, thanks. I must have previously assumed that the error would be raised on the next request, but this makes more sense. Is it worth expanding on the definition of the "error" event in the documentation to include examples like this? It's a little Spartan at the moment. |
@arthurschreiber thanks for doing this. Good call on fixing up the transaction path. Related: I just spent this morning trying to get tests passing on tedious-connection-pool so that I could potentially fix the second part of the problem noted here: tediousjs/tedious-connection-pool#23 But I ran out of time for now. The test suite seems to be a bit crufty and requires more debugging time than I have this second. I hope to look at this sooner or later but just wanted to mention it as I still believe this above pull request doesn't have an effect when using the pool because the connection emits the connection error before calling the socket request: https://github.com/pekim/tedious/blob/arthur/fixup-325/src/connection.js#L485 and because of this... the pool calls connection.close() here: https://github.com/pekim/tedious-connection-pool/blob/master/lib/connection-pool.js#L85 which causes the driver to transition to STATE.FINAL before trying to dispatch the socketError event so the request callback is still never called. I think dispatching the socketError before emitting the connection error event will fix it but I didn't want to try that until I got all the current connection pool tests passing. However currently these tests are failing in the pool:
|
I checked what some of the "core" node.js modules (e.g. I think the easiest fix would be if the pool would wrap the |
Actually, there is no need to call |
@ashelley I'm gonna merge this as-is. Can you please check again if your issue in the connection pool module gets resolved if you remove the |
Forward socket errors to request callbacks.
@arthurschreiber I'm looking into this but having issues with the tedious-connection-pool tests, trying to get to the bottom of it. In the meantime I'd say it sounds sane that if the connection pool simply didn't call connection.close() when err.code === 'ESOCKET' this should fix the issue. |
hello @arthurschreiber I have created a pull request here for the above discussed problem with the connection pool after the above patch gets merged: tediousjs/tedious-connection-pool#24 |
@arthurschreiber Hi, I'm the maintainer of tedious-connection-pool. This doesn't sit right with me. Why does calling My library aside, I think many users would assume they should always close their connections after an error to avoid leaking the connection. I doesn't seem right that the user should have to check what type of error occurred to know if it's safe to call |
@ben-page Thanks for chiming in here. Let me try to explain this a bit. In all instances where the Now, if an error on the underlying socket happens, tedious first emits an Does this make things a bit clearer? |
Yes, thank you for your response. There is a huge difference between never needing to call |
Yep, I agree. |
This is based on #325 - thanks to @ashelley for the bug report and initial work.
On top of the original change, it also updates the
Connection#transaction
helper to work correctlyin case a socket error has happened.
Closes #325.