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

[now dev] Memoize the getNowConfig() promise #2561

Merged
merged 1 commit into from Jul 16, 2019

Conversation

TooTallNate
Copy link
Member

The getNowConfig() function gets invoked frequently, and it is also async and makes mutations to the cached now config object. This ends up being a race condition when getNowConfig() is invoked concurrently, since one of the invocations may end up with an incomplete NowConfig object (namely, with missing builds/routes arrays due to the zero-config processing).

This change makes it so that there's only one getNowConfig() invocation being executed at a time, and other concurrent executions will await the same promise that the original invocation is responsible for.

The `getNowConfig()` function gets invoked frequently, and it is also
async and makes mutations to the cached now config object. This ends
up being a race condition when `getNowConfig()` is invoked concurrently,
since one of the invocations may end up with an incomplete `NowConfig`
object (namely, with missing `builds`/`routes` arrays due to the
zero-config processing).

This change makes it so that there's only one `getNowConfig()` invocation
being executed at a time, and other concurrent executions will await the
same promise that the original invocation is responsible for.
@codecov-io
Copy link

Codecov Report

Merging #2561 into canary will increase coverage by 0.03%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           canary    #2561      +/-   ##
==========================================
+ Coverage   13.65%   13.68%   +0.03%     
==========================================
  Files         256      256              
  Lines        9435     9439       +4     
  Branches     1078     1078              
==========================================
+ Hits         1288     1292       +4     
+ Misses       8023     8022       -1     
- Partials      124      125       +1
Impacted Files Coverage Δ
src/util/dev/server.ts 64.27% <80%> (-0.03%) ⬇️
src/util/metrics.ts 68.18% <0%> (+6.64%) ⬆️

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 930648d...996a519. Read the comment docs.

Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Nice 👍

@TooTallNate TooTallNate merged commit 00437fe into canary Jul 16, 2019
@TooTallNate TooTallNate deleted the update/now-dev-memoize-now-config-promise branch July 16, 2019 21:27
AndyBitz pushed a commit that referenced this pull request Jul 17, 2019
The `getNowConfig()` function gets invoked frequently, and it is also
async and makes mutations to the cached now config object. This ends
up being a race condition when `getNowConfig()` is invoked concurrently,
since one of the invocations may end up with an incomplete `NowConfig`
object (namely, with missing `builds`/`routes` arrays due to the
zero-config processing).

This change makes it so that there's only one `getNowConfig()` invocation
being executed at a time, and other concurrent executions will await the
same promise that the original invocation is responsible for.
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.

None yet

4 participants