-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Cleanly handle missing stream error on COPY operation. Closes #241 #242
Conversation
Actually I'm not sure this commit does a good job. Putting an attempt to copy from stdin under testing finds the connection kind of hanging forever. What's the message that should be sent from Query to signal completion ? |
The problem with my change is that although it succeeds in returning something to the caller, fails to reset the connection back into a useful state:
|
It seems that you are doing copy from in wrong way. There are special methods for this - copyTo and copyFrom, |
Yeah but my main concern here is avoiding an exception, which kills the service I'm running. |
This version works better (doesn't throw) but also doesn't report any error, which is not good
Beside, it would be good to generally avoid throwing exception on unexpected server responses. |
Is this situation form #241?, If it is - problem is that copy operations switches postgres in special subprotocol, in which it does not respond to common messages. If you want to return it normal state you need to send CopyFail
But this situation will appear only if use copy to copy from query from query method |
Yep, it makes sense. |
Much better now (yes, it's from #241).
And here's the current output.
|
according to postgres documentation: |
Also If you try to write defence from incorrect api usage, maybe it's easier to parse query, understand that it's copy to/copy from and report error before actually doing query? |
I tried an expensive query and verified that 'copyData' even is not fired before the query completes, so backend is still busy, too late to cancel. Parsing the query sounds very error prone to me. |
You can try to cancel query on copyOutResponse event (it is not used now, but it is marker event, that means that "copy to" query was parsed by database and database was switched to data transfer subprotocol) |
Seems to be out of my reach. events.js:68 Do you want to try this yourself ? |
Yes, I can try, but it may take few days to find time to do this. |
For the time being could you merge this pull and tag a new release The only thing missing is an error message on COPY TO (the code |
You guys were up late last night! or early. Or not in US timezone. 😄 Will merge this today. Thanks for looking into this. I'm totally with you on not throwing exceptions...exceptions are very not the node way. |
Cleanly handle missing stream error on COPY operation. Closes #241
Rather than killing on uncaught exception, this patch invokes the callback with an appropriate error message when no stream is defined to copy to and from