nanjiek commented on PR #3054:
URL: https://github.com/apache/dubbo-go/pull/3054#issuecomment-3415876920
### 1. Where the error occurs
The error happens in `registry/base_configuration_listener.go:65`, inside
the method `BaseConfigurationListener.InitWith()`:
```go
if rawConfig, err := bcl.dynamicConfiguration.GetRule(key,
config_center.WithGroup(constant.Dubbo)); err != nil {
bcl.configurators = []config_center.Configurator{}
return
} else if len(rawConfig) > 0 {
if err := bcl.genConfiguratorFromRawRule(rawConfig); err != nil {
logger.Error("bcl.genConfiguratorFromRawRule(rawConfig:%v) =
error:%v", rawConfig, err)
}
}
```
---
### 2. Root cause — configuration format mismatch
The **core issue** is a **format mismatch**.
In `config_center/mock_dynamic_config.go` (lines 59–82), the
`MockDynamicConfiguration` is initialized with content in **properties format**:
```go
dynamicConfiguration.content = `
dubbo.consumer.request_timeout=5s
dubbo.consumer.connect_timeout=5s
dubbo.application.organization=ikurento.com
...
`
```
However, in `config_center/parser/configuration_parser.go`, the
`ParseToUrls()` method (line 118) expects the content to be in **YAML format**
for the `ConfiguratorConfig` structure:
```go
func (parser *DefaultConfigurationParser) ParseToUrls(content string)
([]*common.URL, error) {
config := ConfiguratorConfig{}
if err := yaml.Unmarshal([]byte(content), &config); err != nil {
return nil, err
}
// ...
}
```
---
### 3. Error trigger flow
Here’s how the error happens step by step:
1. **Initialization phase**:
The test calls `exporterNormal()` → `regProtocol.Export()` → which
initializes `BaseConfigurationListener`.
2. **Configuration retrieval**:
`BaseConfigurationListener.InitWith()` calls `GetRule()` to fetch the
existing configuration from the mock config center.
3. **Incorrect format returned**:
`MockDynamicConfiguration.GetRule()` returns the **properties-format**
content.
4. **Parsing failure**:
Inside `genConfiguratorFromRawRule()`, it calls `ParseToUrls()`, which
tries to parse the properties string as YAML — causing a parsing error.
---
### 4. Why the test still passes
Even though an error is logged, the test **passes** successfully for several
reasons:
1. **Error is gracefully handled**
The failure in `genConfiguratorFromRawRule()` is only logged using
`logger.Error`, not returned or propagated, so the test execution continues.
2. **Subsequent correct configurations**
The test later calls `MockServiceConfigEvent()` and
`MockApplicationConfigEvent()`, which send properly formatted **YAML
configurations**:
```go
func (c *MockDynamicConfiguration) MockServiceConfigEvent() {
config := &parser.ConfiguratorConfig{
ConfigVersion: "2.7.1",
Scope: parser.GeneralType,
Key: mockServiceName,
Enabled: true,
Configs: []parser.ConfigItem{...},
}
value, _ := yaml.Marshal(config) // Correct YAML format
// ...
}
```
3. **Final configuration takes effect**
Through the configuration event mechanism, the correctly formatted YAML
content overrides the faulty one from initialization.
As a result, the test assertions still succeed even though the earlier
parsing error occurred.
---
--
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]