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

http: fix a bug that would cause runtimeConfig to be cached #9923

Merged
merged 3 commits into from Mar 25, 2021

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Mar 24, 2021

This bug would result in the UI not having the correct settings in Consul enterprise, which could produce many warnings in the logs.

This bug occurred because the index page, which includes a map of configuration was rendered when the HTTPHandler is first created. This PR changes the UIServer to instead render the index page when the page is requested.

The rendering does not appear to be all that expensive, so rendering it when requested should not cause much extra latency.

Also includes a bit of cleanup to remove some unnecessary args, and unnecessary function wrapping.

This bug only exists in 1.9.x, so I think we only need one backport.

This bug would result in the UI not having the correct settings in
Consul enterprise, which could produce many warnings in the logs.

This bug occured because the index page, which includes a map of configuration
was rendered when the HTTPHandler is first created. This PR changes the
UIServer to instead render the index page when the page is requested.

The rendering does not appear to be all that expensive, so rendering it
when requested should not cause much extra latency.
@vercel vercel bot temporarily deployed to Preview – consul March 24, 2021 18:52 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 24, 2021 18:52 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 24, 2021 19:38 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 24, 2021 19:38 Inactive
// Reload config in case it's changed
state := h.getState()
cfg := h.getRuntimeConfig()
Copy link
Member

@rboyer rboyer Mar 24, 2021

Choose a reason for hiding this comment

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

This may be nil and prior code forced a quick panic in that case which is no longer present. Just wanted to verify that was intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, some callers did explicitly panic with a custom message, and others did not. In practice it should never be nil, but if there is a bug, it will panic on the next line either way. A panic on line 140 should be unambiguous because the UIConfig field is not a pointer, so only cfg could be nil.


var fs http.FileSystem
func (h *Handler) handleIndex() (http.Handler, error) {
cfg := h.getRuntimeConfig()
Copy link
Member

Choose a reason for hiding this comment

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

same comment about this returning nil

Copy link
Member

@rboyer rboyer left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks Daniel.

@dnephin dnephin merged commit 8d25f9a into master Mar 25, 2021
@dnephin dnephin deleted the dnephin/fix-ui-config branch March 25, 2021 16:26
@hashicorp-ci
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/342452.

@hashicorp-ci
Copy link
Contributor

🍒✅ Cherry pick of commit 8d25f9a onto release/1.9.x succeeded!

hashicorp-ci pushed a commit that referenced this pull request Mar 25, 2021
http: fix a bug that would cause runtimeConfig to be cached
dizzyup pushed a commit that referenced this pull request Apr 21, 2021
http: fix a bug that would cause runtimeConfig to be cached
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