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

worker: move api.BasePath setup to the start of the funcs #4328

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Aug 26, 2024

I find it slightly eaiser to read this code when
api.BasePath = conf.BasePath is right at the top as it's unrelated to the parsing code below.

Note that the code itself is problematic:

  • api.BasePath is global but client is not, this means that multiple client with different configs will result in api.BasePath being potentially wrong
  • api.BasePath is set in a non-thread safe manner

Changing is a bigger job but we might consider it (IMHO).

I find it slightly eaiser to read this code when
`api.BasePath = conf.BasePath` is right at the top as it's
unrelated to the parsing code below.

Note that the code itself is problematic:
- api.BasePath is global but client is not, this means that
  multiple client with different configs will result in
  api.BasePath being potentially wrong
- api.BasePath is set in a non-thread safe manner

Changing is a bigger job but we might consider it (IMHO).
@schuellerf
Copy link
Contributor

schuellerf commented Aug 26, 2024

despite this flaw in design, I think we can as well "assert" on startup (as a kind of mitigation) somehow that there is no second client and no second config, as this won't happen I guess
This would be a worker connected to two composers right?

mvo5 added a commit to mvo5/osbuild-composer that referenced this pull request Aug 26, 2024
The `api.BasePath` is package global but the way it is used is that
multiple clients can (potentially) have different BasePath and
the way it is written right now could lead to confusing bugs.

This commit tweaks the `api` package so that `BasePath` does not
need to be set. The only place that this is needed is for the
`api.APIError()` which can just get the basePath as an argument.
With that we also need a helper to construct the api error handler
from the static HTTPErrorHandler to a dynamic MakeHTTPErrorHandler()
that will return a handler for the given basePath.

This should make osbuild#4328
obsolete.
@thozza thozza merged commit 2442bae into osbuild:main Aug 28, 2024
47 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants