Skip to content
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(close): ensure in-flight messages are drained #952

Merged
merged 4 commits into from Apr 15, 2020

Conversation

jeffijoe
Copy link
Contributor

@jeffijoe jeffijoe commented Apr 9, 2020

Track in-flight requests and add an onDrain deferred that resolves when all in-flight ack/modAcks are done.

Fixes #951

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Apr 9, 2020
@jeffijoe
Copy link
Contributor Author

jeffijoe commented Apr 9, 2020

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Apr 9, 2020
@feywind
Copy link
Collaborator

feywind commented Apr 10, 2020

Thanks for the contribution, @jeffijoe ! I'll review in just a sec.

const origSendBatch = patchedQueue._sendBatch;
const log: string[] = [];
const sendDone = defer();
patchedQueue._sendBatch = async function _sendBatch(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this might be done using sandbox.stub just to be consistent with the rest of the tests. I'm going to ask someone who knows a bit more about Sinon than me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean just the patching of the method?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Sorry for not being clear there. On second thought, I think it's not a big deal because you're making your own MessageQueue anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to stay consistent with the rest of the source but I was not sure how else I would pull this off. Do you have any suggestions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could probably use the sandbox on the existing messageQueue._sendBatch, if you wanted to be a bit more consistent with the other tests. That might be nice if we change something about how the "global" MessageQueue is wired up under describe later, but I don't think it's worth spending much time on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it and rebased to tip of master but now other unrelated tests are failing. Is master healthy right now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be, but we have been tracking down some flaky tests for a bit, too. I'll look.

@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 10, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 10, 2020
@jeffijoe
Copy link
Contributor Author

If you are wondering about the force-pushes, I am just rebasing to latest master.

@feywind
Copy link
Collaborator

feywind commented Apr 13, 2020

Yep, no worries on the rebase!

@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 13, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 13, 2020
@feywind
Copy link
Collaborator

feywind commented Apr 13, 2020

I think the rebase is actually confusing our CI bots, so you might want to just use merge to get the tests running automatically.

@jeffijoe
Copy link
Contributor Author

Kokoro seemed to have issues even with my first non-rebased commit though? I can push a dummy commit if you want and see if it resolves anything?

@feywind
Copy link
Collaborator

feywind commented Apr 13, 2020

Sure, let's try it for science :)

It looks like the checks are passing at this point. Hopefully we'll have our automated sample failure bot going on this repo soon.

if (deferred) {
deferred.resolve();
}

if (this.numInFlightRequests === 0 && this._onDrain) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, super minor thing here that I thought @bcoe was going to comment on - to be overly defensive, it might be nice to make this <= 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! :)

@feywind
Copy link
Collaborator

feywind commented Apr 13, 2020

Apparently the actual issue with the CI here is that Kokoro is having issues. I'll try to get this merged tomorrow.

Track in-flight requests and add an `onDrain`deferred that resolves when all in-flight requests are done.
@bcoe bcoe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 15, 2020
@feywind feywind added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 15, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 15, 2020
@feywind feywind merged commit 93a2bd7 into googleapis:master Apr 15, 2020
feywind added a commit to feywind/nodejs-pubsub that referenced this pull request Apr 22, 2020
Track in-flight requests and add an `onDrain`deferred that resolves when all in-flight requests are done.

Co-authored-by: Megan Potter <57276408+feywind@users.noreply.github.com>
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
feywind added a commit that referenced this pull request Apr 24, 2020
* fix(close): ensure in-flight messages are drained (#952)

Track in-flight requests and add an `onDrain`deferred that resolves when all in-flight requests are done.

Co-authored-by: Megan Potter <57276408+feywind@users.noreply.github.com>
Co-authored-by: Benjamin E. Coe <bencoe@google.com>

* chore: update equal to strictEqual for linter changes

Co-authored-by: Jeff Hansen <jeffijoe@hotmail.com>
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition when flushing message queues while a batch is in-flight
5 participants