Open
Description
When updating configuration file with invalid yaml format (e.g. incorrect indentation), the application panics with the following error:
panic: sync/atomic: store of nil value into Value
goroutine 10 [running]:
sync/atomic.(Value).Store(...)
sync/atomic/value.go:49 +0xe5
github.com/go-kratos/kratos/v2/config.readValue(...)
.../config/reader.go:147 +0x10b
github.com/go-kratos/kratos/v2/config.(reader).Value(...)
.../config/reader.go:64 +0x9a
github.com/go-kratos/kratos/v2/config.(config).watch.func1(...)
.../config/config.go:85 +0xe6
Steps to reproduce:
- Start the application with initial config:
log:
level: debug
- Update the config file with incorrect indentation:
log:
level: info # incorrect indentation
Expected behavior:
- The application should handle invalid configuration gracefully
- Log an error message about invalid configuration format
- Keep using the previous valid configuration
Actual behavior:
- The application panics due to nil value in atomic.Store
- No error handling for invalid configuration format
- Service interruption
Suggestion:
- Add validation for configuration format before applying changes
- Handle nil values gracefully in config.readValue
- Log detailed error messages about configuration format issues
- Keep using the last known good configuration when encountering errors
Environment:
- Kratos version: v2.8.4
- Go version: 1.24.2
- OS: darwin
Metadata
Metadata
Assignees
Labels
Something isn't workingSomething isn't working