8000 [BUG] Config hot reload panic when yaml format is invalid · Issue #3626 · go-kratos/kratos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
8000 Skip to content
[BUG] Config hot reload panic when yaml format is invalid #3626
Open
@alariczq

Description

@alariczq

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:

  1. Start the application with initial config:
log:
  level: debug
  1. 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:

  1. Add validation for configuration format before applying changes
  2. Handle nil values gracefully in config.readValue
  3. Log detailed error messages about configuration format issues
  4. 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

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0