Skip to content

fix: Prevent closing the portal twice #2120

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

Closed
wants to merge 3 commits into from
Closed

fix: Prevent closing the portal twice #2120

wants to merge 3 commits into from

Conversation

matthieusieben
Copy link
Contributor

Fixes #2119

@matthieusieben
Copy link
Contributor Author

Not sure this is the right way to fix this (might be better to check in _closePortal() itself)

@brianc
Copy link
Owner

brianc commented Feb 26, 2020

ah dang - w/ the race condition situation I'm guessing there's no good way to write a test for this?

@matthieusieben
Copy link
Contributor Author

Not sure indeed. Maybe we can find a way to force a call to close() right after we get a first row (e.g. by monkey matching the listener?), and then wait for the complete command listener to kick in.

I am not too familiar with this lib's internals so I don't feel too confortable fixing it myself.

@matthieusieben
Copy link
Contributor Author

Hey @brianc did you get time to look into this ?

@brianc
Copy link
Owner

brianc commented May 5, 2020

Yeah I spent some time this morning looking at this, trying to force the error to happen...I am not able to simulate the race condition here. I'm definitely down w/ you giving it a shot through any level of monkey patching you think would accurately recreate it. If you can't, I can just merge this as it the behavior itself makes sense...though I do think moving this.state = 'done' into _closePortal and having that function also check the state and no-op out if it's already switched into done is probably more "clean" in that the state is checked & updated in the same place that way.

Sorry for the delay. Thoughts?

@matthieusieben
Copy link
Contributor Author

I guess you could monkey patch by adding a setTimeout around everything inside Cursor.prototype.close.

I made the suggested change though I am not sure about calling _closePortal from handleReadyForQuery. I have no idea what the internal state machine of a cursor is inside of PG (where wan I find this documentation?).

@matthieusieben
Copy link
Contributor Author

Hey @brianc did you get time to look into this ?

@brianc
Copy link
Owner

brianc commented Jun 3, 2020

Hey sorry for the delay! I was out on vacation & just getting back...I'll take a look at this tomorrow! ❤️

@matthieusieben
Copy link
Contributor Author

closing in favor of #2609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cursor closed twice when used in async iterable
2 participants