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: modify the BatchHttpLink to have each timer when the batch key is different #10408

Merged
merged 5 commits into from
Jan 26, 2023

Conversation

zlrlo
Copy link
Contributor

@zlrlo zlrlo commented Jan 5, 2023

fix #10205
In version 3.7.3, I found that the mutation not issued on network requests in useEffect or onCompleted.
If there is a query request after the mutation request, the query cleared the timer for the mutation.
So I made a timer by separating it with a batch key and this problem was fixed.

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@apollo-cla
Copy link

@zlrlo: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@changeset-bot
Copy link

changeset-bot bot commented Jan 5, 2023

🦋 Changeset detected

Latest commit: ea7ec33

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@zlrlo zlrlo force-pushed the fix-scheduleQueueConsumption branch 2 times, most recently from 34a0f6a to c8b92fa Compare January 5, 2023 10:50
@bignimbus
Copy link
Contributor

Hi @zlrlo 👋🏻 thanks for opening this PR! It looks like there are some failing tests, mind taking a closer look at those? Feel free to ask questions in this PR 🙏🏻

@zlrlo zlrlo force-pushed the fix-scheduleQueueConsumption branch from c8b92fa to f583cc8 Compare January 9, 2023 04:39
@alessbell alessbell added the 🏓 awaiting-team-response requires input from the apollo team label Jan 9, 2023
@bignimbus bignimbus self-requested a review January 10, 2023 18:43
Comment on lines 214 to 218
clearTimeout(this.scheduledBatchTimerByKey.get(key));
this.scheduledBatchTimerByKey.set(key, setTimeout(() => {
this.consumeQueue(key);
}, this.batchInterval);
}, this.batchInterval));

Choose a reason for hiding this comment

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

There doesn't seem to be a part that deletes the timer in scheduledBatchTimersByKey.

Choose a reason for hiding this comment

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

after consume, don't we remove timer from map?
just like this.scheduledBatchTimerByKey.delete(key)

Copy link
Contributor

@bignimbus bignimbus left a comment

Choose a reason for hiding this comment

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

Thanks again @zlrlo for submitting this PR. I rebased from main and pushed @kang-heewon's suggestion. I also added an inline comment to explain that timeout = real failure in the test case @zlrlo added. We don't have a runnable reproduction handy so if possible please verify that the latest version of this branch works for you on your end. I think we're close to being able to merge this 🙏🏻

this.consumeQueue(key);
}, this.batchInterval);
this.scheduledBatchTimerByKey.delete(key);
Copy link

@kang-heewon kang-heewon Jan 26, 2023

Choose a reason for hiding this comment

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

Shouldn't this delete be done once more right after clearTimeout?
It is not deleted from the map when clearTimeout runs. @bignimbus

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @kang-heewon - I felt that would be redundant given that we're setting a new value for that key on line 215. Can you help me understand your suggestion more?

Choose a reason for hiding this comment

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

Oh, you're right. It's my mistake.

Copy link
Contributor

@bignimbus bignimbus left a comment

Choose a reason for hiding this comment

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

I was able to validate this fix on this reproduction scenario, forked from @vpotapchuk's example here: #10205 (comment)

@bignimbus bignimbus removed the 🏓 awaiting-team-response requires input from the apollo team label Jan 26, 2023
@bignimbus bignimbus merged commit 55ffafc into apollographql:main Jan 26, 2023
@github-actions github-actions bot mentioned this pull request Jan 26, 2023
@zlrlo
Copy link
Contributor Author

zlrlo commented Jan 30, 2023

Hi @bignimbus The latest version of this branch is working well for us. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in BatchHttpLink with v3.7.0: queries hang and are not issued on network requests
5 participants