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: Fix client pooling for long-lived listens #614

Merged
merged 3 commits into from May 10, 2019
Merged

Conversation

wilhuff
Copy link
Contributor

@wilhuff wilhuff commented May 10, 2019

Fixes firebase/firebase-admin-node#499

Previously _initializeStream returned a Promise that indicated that the
stream was "released", i.e. that it was was ready for attaching
listeners.

#256 Added pooled clients and changed the
callers of _initializeStream to reuse this promise such that when it was
resolved, the stream could be returned to the pool. This works when
listeners are short-lived, but fails when listeners run indefinitely.

This change arranges to release the clients back to the pool only after
the stream has completed, which allows an arbitrary number of indefinite
listens to run without problems.

This turns out to be fiendishly difficult to test given the current structure
of the code. A second pass at this that reformulates this as just another
stream that composes with the others would make this easier to understand and
test. For now, this fix unblocks the customers waiting on the referenced issue.

These names suggest that the returned Promise represents a stream that
has completed and whose client is suitable to release back into the
pool, when in fact, it only represents that the stream has successfully
initialized.
Previously _initializeStream returned a Promise that indicated that the
stream was "released", i.e. that it was was ready for attaching
listeners.

#256 Added pooled clients and changed the
callers of _initializeStream to reuse this promise such that when it was
resolved, the stream could be returned to the pool. This works when
listeners are short-lived, but fails when listeners run indefinitely.

This change arranges to release the clients back to the pool only after
the stream has completed, which allows an arbitrary number of indefinite
listens to run without problems.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 10, 2019
@wilhuff wilhuff requested a review from var-const May 10, 2019 08:36
@codecov
Copy link

codecov bot commented May 10, 2019

Codecov Report

Merging #614 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
+ Coverage   61.18%   61.29%   +0.11%     
==========================================
  Files          21       21              
  Lines        3375     3385      +10     
  Branches      453      454       +1     
==========================================
+ Hits         2065     2075      +10     
  Misses       1250     1250              
  Partials       60       60
Impacted Files Coverage Δ
dev/src/index.ts 94.94% <100%> (+0.08%) ⬆️
dev/src/pool.ts 97.5% <100%> (+0.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c119250...be865dc. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented May 10, 2019

Codecov Report

Merging #614 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
+ Coverage   61.18%   61.29%   +0.11%     
==========================================
  Files          21       21              
  Lines        3375     3385      +10     
  Branches      453      454       +1     
==========================================
+ Hits         2065     2075      +10     
  Misses       1250     1250              
  Partials       60       60
Impacted Files Coverage Δ
dev/src/index.ts 94.94% <100%> (+0.08%) ⬆️
dev/src/pool.ts 97.5% <100%> (+0.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c119250...be865dc. Read the comment docs.

@var-const var-const assigned wilhuff and unassigned var-const May 10, 2019
@wilhuff wilhuff merged commit 479bc9c into master May 10, 2019
@wilhuff wilhuff deleted the wilhuff/fix-pool branch May 10, 2019 17:10
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.

Firestore: Deadline Exceeded, retrying doesn't help
3 participants