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

calling Load(config) from modules #4464

Closed
aep opened this issue Dec 7, 2021 · 7 comments
Closed

calling Load(config) from modules #4464

aep opened this issue Dec 7, 2021 · 7 comments

Comments

@aep
Copy link

aep commented Dec 7, 2021

the website mentions dynamic configuration but i haven't found any plugin that dynamically loads configs, and no documentation.

Is it ok to call Load() from a module?

caddy/caddy.go

Line 102 in e7457b4

func Load(cfgJSON []byte, forceReload bool) error {

how do we avoid the loop when caddy instantiates the module after reloading the config?

@francislavoie
Copy link
Member

You're right, we haven't really documented how to use dynamic config loading. There's an explanation in the PR where it was introduced though, see the 3rd part #3994

@francislavoie francislavoie added the documentation 📚 Improvements or additions to documentation label Dec 7, 2021
@aep
Copy link
Author

aep commented Dec 7, 2021

thanks. the linked PR doesnt explain if Load can be called at any point tho, as it is going to happen with a dynamic config.
Instead it seems to be intended for static configs loaded from a remote location that only gets loaded once.

@francislavoie
Copy link
Member

Right, the other part is #4246 which added periodically pulling the config from the loader. So you could implement your own loader (a module in the namespace caddy.config_loaders).

@aep
Copy link
Author

aep commented Dec 7, 2021

which would only allow polling instead of loading it on change tho.
i could poll every 1ms i guess, but then again i might as well just call the http/admin endpoint from itself, which seems to support reloading on demand.

@francislavoie
Copy link
Member

francislavoie commented Dec 7, 2021

but then again i might as well just call the http/admin endpoint from itself

The issue with that is the risk of deadlocks, cause the thing making the request will try to get shut down by the config loader which is swapping out the old config with the new, but if it can't shut down the old config (because there's still a pending request), it'll never be able to load the new config.

But yeah, I'd suggest configuring some low polling rate (50ms or 100ms should be more than frequent enough) and do a quick check to see if you should attempt to load a new one or not.

Noticed an issue with that idea though, /cc @mholt, the ConfigLoader interface returns ([]byte, error), so either you give a config that it'll attempt to load again, or it'll print an error to the logs. I don't really like this. I think it should be something like ([]byte, bool, error) so we can return false to skip loading (as in, loading is unnecessary at this time) instead of returning an error which would flood the logs if the interval is short. That feature is still marked "experimental", so we can probably make that change now.

@mholt
Copy link
Member

mholt commented Feb 2, 2022

@francislavoie How about instead we allow returning nil, nil to indicate that there's no new config to load.

Would this be helpful / solve the problem?

@aep
Copy link
Author

aep commented Feb 2, 2022

ah, hm this is awkward. I found some other issues with async loading but don't remember since we ended up not using Caddy.

I think we should just close this.

@mholt mholt closed this as completed Feb 2, 2022
@mholt mholt removed the documentation 📚 Improvements or additions to documentation label Feb 2, 2022
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

No branches or pull requests

3 participants