Status Update
Comments
da...@gmail.com <da...@gmail.com> #2
This issue is not specific to the HTTP protocol, but also with SSH a wrong hostname will be used in the chang URL.
da...@gmail.com <da...@gmail.com> #3
I've spent a few hours trying to understand what's going on and try to fix this. The root cause seems to be the fact that parts of the receive commits command are done on a different thread, and the fact that the virutalhost
plugin uses a combination of HttpFilter
and ThreadLocal
to obtain and store the server name from HttpRequest
.
The URL used in the command output is constructed using DynamicItem<UrlFormatter>
, which in the DefaultUrlFormatter
is obtaining hostname via constructor injection of @CanonicalWebUrl Provider<String>
. It is important to note that the DefaultUrlFormatter
is marked with @Singleton
, which means that after initial creation the canonical web url will not change. But removing the annotation doesn't change anything. The VirtualHostHttpCanonicalWebUrlProvider
will not be able to get the server name from the thread local anyway.
Digging deeper, the DynamicItem<UrlFormatter>
is used in ChangeUtil#getChangeIdsFromFooter()
, which is also a @Singleton
(removing that annotation also didn't help), then eventually is called from ReceiveCommits#processCommandsUnsafe()
. On this level, we have access to requestScopePropatator
which will propagate the HTTP request scope to the background thread. This means we can do requestScopeapropagator(() -> processCommandsUnsafe(commands, progress)).run()
and hope that @CanonicalWebUrl
will be calculated correctly. Unfortunately, this way we'll be using members of ReceiveCommits
that were created out of the HTTP scope and we'll still get an incorrect result.
I've also tried injecting Provider<ChangeUtil>
into ReceiveCommits
, hoping that this would create a new instance on each get()
and resolve its dependencies in the context of the HTTP request. Unfortunately, no luck with that.
Maybe, extracting processCommandsUnsafe()
to a class and injecting its provider into ReceiveCommits
, then using that provider in requestScopePropagator.wrap()
could solve this problem. But this feels too invasive for such a trivial problem.
For now, I'm out of ideas. This is clearly a problem with Guice scopes and injectors but it's not easy to be solved.
ap...@google.com <ap...@google.com> #4
Branch: stable-3.7
commit 4350b3d5700964abd22d7d567e7a5ff38ce4bc8f
Author: Dariusz Luksza <dariusz.luksza@gmail.com>
Date: Fri Nov 24 18:41:07 2023
Ensure proper canonical web url in Git over HTTP
Make sure that the current HttpServletRequest is propagated to
HttpCanonicalWebUrlProvider in Git over HTTP context. So that the output
of git push command has the proper server URL.
This also deletes the "manual injection" of
`Provider<HttpServletRequest>` from the `webInjector` in the `Daemon`
class. That injection doesn't make sense for this class, as
`HttpCanonicalWebUrlProvider` is not a singleton, which means a new
instance will be created each time it is obtained from Guice. So in the
`Daemon.java`, the instance will be created on the spot, then the HTTP
request provider will be set on it and that very instance will be
disposed.
This is fixing a problem encountered in the virutalhost plugin, where
despite proper configuration for tenant canonical web URL, the git push
output would use the value of `gerrit.canonicalweburl` configuration
option.
Bug:
Release-Notes: Fix canonical web url binding in Git over HTTP
Change-Id: I82891b25bd23bb8467a2bb3fa829e58846140faf
M java/com/google/gerrit/httpd/GuiceRequestScopePropagator.java
M java/com/google/gerrit/pgm/Daemon.java
ap...@google.com <ap...@google.com> #5
Branch: master
commit f94abd64a288e5c25adee4d3e88bf79990f77c5b
Author: Dariusz Luksza <dariusz.luksza@gmail.com>
Date: Sat Nov 25 08:34:53 2023
Provide virtual host name in git command outputs
When pushing changes to Gerrit, the URL for each of them will be
returned in the push command output. Previously those URLs used the
name of the main host.
To fix this, `VirtualHostHttpCanonicalWebUrlProvider` needs to be
aware of the optional request provider, so that we can extract the
server name from the request processed on a different thread where our
`ThreadLocal` was not set. Additionally, it needs to keep its state as
a singleton.
Bug:
Change-Id: I8259aa99b9924daea9749a999f2fee81c7bf08ed
M src/main/java/com/gerritforge/gerrit/modules/virtualhost/VirtualHostHttpCanonicalWebUrlProvider.java
da...@gmail.com <da...@gmail.com> #6
🆗
09392430244
در تاریخ پنجشنبه ۲۸ مارس ۲۰۲۴، ۰۲:۲۸ <buganizer-system@google.com> نوشت:
Description
Context
One Gerrit primary review.mycompany.com configured with one virtual domain, review-1.mycompany.com
Example:
Operations
Create a new change on project-1, and push for review.
Expected behaviour
The output display the change URL using the virtual domain:
Observed behaviour
The output display the change URL using the actual domain: