AlexStocks commented on issue #3151:
URL: https://github.com/apache/dubbo-go/issues/3151#issuecomment-4059291655
I traced through the code and the root cause is a **storage-vs-retrieval
mismatch** for the application name.
**How it's stored** (`registry/directory/directory.go:88-96`):
```go
application := config.GetRootConfig().Application
url.SetAttribute(constant.ApplicationKey, application) // stores
*global.ApplicationConfig as attribute
```
**How polaris router reads it** (`cluster/router/polaris/router.go:57-61`):
```go
applicationName := url.GetParam(constant.ApplicationKey, "") // looks
for string param — always ""
applicationName = url.SubURL.GetParam(constant.ApplicationKey, "") // same —
always ""
// → "polaris router must set application name"
```
The application is stored as a structured `*global.ApplicationConfig` object
in URL **attributes**, but the polaris router tries to read it as a URL
**parameter** (plain string). They never meet.
**Fix** — update `cluster/router/polaris/router.go` to read from attributes:
```go
func newPolarisRouter(url *common.URL) (*polarisRouter, error) {
var applicationName string
// first try URL param (backward compat)
applicationName = url.GetParam(constant.ApplicationKey, "")
// then try attribute (current storage path)
if applicationName == "" {
if appConfRaw, ok := url.GetAttribute(constant.ApplicationKey); ok {
if appConf, ok := appConfRaw.(*global.ApplicationConfig); ok &&
appConf != nil {
applicationName = appConf.Name
}
}
}
// fallback to SubURL
if applicationName == "" && url.SubURL != nil {
applicationName = url.SubURL.GetParam(constant.ApplicationKey, "")
if applicationName == "" {
if appConfRaw, ok :=
url.SubURL.GetAttribute(constant.ApplicationKey); ok {
if appConf, ok := appConfRaw.(*global.ApplicationConfig); ok
&& appConf != nil {
applicationName = appConf.Name
}
}
}
}
if applicationName == "" {
return nil, fmt.Errorf("polaris router must set application name")
}
// ...
}
```
This is a ~10 line change. The same pattern is already used elsewhere in the
codebase (e.g. `registry/directory/directory.go:223`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]