-
-
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
Fix pg-query-stream implementation #2051
Conversation
There were some subtle behaviors with the stream being implemented incorrectly & not working as expected with async iteration. I've modified the code based on #2050 and comments in #2035 to have better test coverage of async iterables and update the internals significantly to more closely match the readable stream interface. Note: this is a __breaking__ (semver major) change to this package as the close event behavior is changed slightly, and `highWaterMark` is no longer supported. It shouldn't impact most usage, but breaking regardless.
Hmmm....a test is failing on node carbon which falls out of LTS in 2 days and will be dropped from pg's support matrix soon after. I wonder if it's just a stream implementation difference on older versions of node? I'll look into this over the weekend & get it figured out...likely just skip that test in the case of node<10. |
The code from #2050 is slightly different than the one I published before. I removed the support for multiple callbacks, as it should not be needed. |
k cool thanks a ton! ill get them synced up
…On Sat, Dec 28, 2019 at 11:34 AM Matthieu Sieben ***@***.***> wrote:
The code from #2050 <#2050>
is slightly different than the one I published before. I removed the
support for multiple callbacks, as it should not be needed.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2051?email_source=notifications&email_token=AAAMHIMSDIYS3KC64JJQWIDQ26EYRA5CNFSM4KAPTIIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHYOTHY#issuecomment-569436575>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAMHIN6MJUI3PTIIPFN7GDQ26EYRANCNFSM4KAPTIIA>
.
|
Another thing: since you are updating the semver, maybe you could remove the |
Another comment, I am not sure what to do with the err argument in the destroy. My supposition is that the error can be used to determine how to properly destroy depending on the error type (eg. Destroyed from within, during a read, or from outside). In either case it is not needed to keep an internal reference to |
great points - i'll do a bit more refactoring and 🔨 on this tomorrow! |
Okay came back & updated this more. Removed the |
Mmmh you removed too much. The _reading was preventing to close the cursor while reading. Not sure how but I did get a connection in an invalid state because of this. |
Also, not sure that you need to call the destroy callback with the provided error. If the stream is destroyed because of an outside error, closing the cursor does not necessarily results in an error. It seems odd to tell the Readable class that "there was an error when destroying the stream" when the error actually originated elsewhere |
Sorry I'm not following what you're saying here exactly. |
Also, if you read the docs: https://nodejs.org/api/stream.html#stream_writable_destroy_err_callback You should re-chek the code from my PR with this in mind |
Yeah I tried to get this to trip w/ various tests but wasn't able to do so...I can put the code back in but feels weird to have code which is effectively not tested against properly since adding or removing doesn't effect the test results. |
Well what does the pg doc says about closing a cursor while reading? And what would happen in the pg-cursor class if more data comes in after it was closed |
|
The docs are a bit unclear on what to pass as an error argument to the callback passed to |
I added a test for this behavior which fails if I remove calling |
Yeah you're right there are some weird edge cases here...I gotta run some errands but I'll try to get back and write tests for more of these edge cases. It's kinda undefined behavior and/or misuse of the cursor itself if you do something like
I quickly tested that and it actually causes some problems so I'll make sure that type of scenario can't be performed through using the stream in any way. |
Okay did some tests - calling |
That seems about right. Note that you can rely on the The |
Now I wouldn't change the behavior of |
Now that I finally got eveything in one repo (yay!) it's much easier to fix things in dependent modules and have those fixes be carried into new ones like this! |
Okay - I think we're good here. Plan on releasing a semver patch bump of pg-cursor & semver major bump (with changelog entry) for pg-query-stream tomorrow. @matthieusieben thanks so much for your help and patience! 🙏 |
You're welcome. |
There were some subtle behaviors with the stream being implemented incorrectly & not working as expected with async iteration. I've modified the code based on #2050 and comments in #2035 to have better test coverage of async iterables and update the internals significantly to more closely match the readable stream interface.
Note: this is a breaking (semver major) change to this package as the close event behavior is changed slightly so it now emits always, instead of improperly being suppressed when manually closing the stream, and
highWaterMark
is no longer supported. It shouldn't impact most usage, but breaking regardless.cc @matthieusieben - I think I covered the tests you were looking for in your previous comment, but please let me know if I missed anything! 🙏