Skip to content

fix(chaoscenter): prevent nil pointer dereference in QueryServerVersion when config is missing#5476

Open
NETIZEN-11 wants to merge 3 commits intolitmuschaos:masterfrom
NETIZEN-11:feature/gitops-probe-sync-5456-recover
Open

fix(chaoscenter): prevent nil pointer dereference in QueryServerVersion when config is missing#5476
NETIZEN-11 wants to merge 3 commits intolitmuschaos:masterfrom
NETIZEN-11:feature/gitops-probe-sync-5456-recover

Conversation

@NETIZEN-11
Copy link
Copy Markdown

Bug Fix

Fixes #5449

This PR resolves a potential nil pointer dereference panic in the QueryServerVersion function located in:

chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go

Previously, the function accessed fields from the result of config.GetConfig(ctx, "version") without verifying whether the returned pointer was nil. In cases where the configuration key does not exist in the database, GetConfig may return (nil, nil), which causes a runtime panic when accessing dbVersion.Key.

Additionally, the code performed a direct type assertion (dbVersion.Value.(string)), which could panic if the stored value is not of type string.

Changes Made

  • Added a nil check for dbVersion returned by config.GetConfig.

  • Implemented a safe type assertion for the Value field.

  • Added descriptive error messages for:

    • Missing server version configuration
    • Invalid configuration value type
  • Ensured the existing function signature and behavior remain unchanged for valid cases.

Result

This change prevents runtime panics and improves the robustness of the server by handling invalid or missing configuration data gracefully.

Example Scenarios Handled

  1. Missing configuration in database

    • Previously caused a nil pointer panic.
    • Now returns a descriptive error.
  2. Invalid value type in configuration

    • Previously caused a type assertion panic.
    • Now returns a safe error.

Impact

This is a non-breaking bug fix that improves defensive error handling without affecting existing functionality.


Types of changes

  • Bugfix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed
  • Lint and unit tests pass locally with my changes

NETIZEN-11 added 3 commits April 9, 2026 11:53
Implements Feature Request litmuschaos#5465 to enable full GitOps synchronization
for Resilience Probes. This allows probes to be defined as YAML manifests
in Git repositories and automatically synced to ChaosCenter.

Key changes:
- Extended GitOps service to detect and process ResilienceProbe manifests
- Added probe parsing logic for all probe types (HTTP, CMD, PROM, K8s)
- Implemented create, update, and delete operations via probe API
- Added comprehensive unit tests for probe sync functionality
- Maintained backward compatibility with existing experiment sync

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
Provides working example manifests for HTTP, CMD, Prometheus, and K8s
probes to help users get started with GitOps probe sync.

Examples include:
- HTTP probe with GET and POST methods
- CMD probe with command execution and comparator
- Prometheus probe with PromQL query
- K8s probe with resource validation
- Comprehensive README with usage patterns

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
Provides complete user documentation for the GitOps probe sync feature
including setup guide, probe manifest specifications, property reference,
troubleshooting, and best practices.

Documentation covers:
- Feature overview and sync flow
- Repository structure guidelines
- Probe manifest format for all probe types
- Complete property reference tables
- Step-by-step usage guide
- Troubleshooting common issues
- Migration guide for existing probes

Signed-off-by: NETIZEN-11 <kumarnitesh121411@gmail.com>
@NETIZEN-11
Copy link
Copy Markdown
Author

Hi @PriteshKiri,

Thanks for pointing it out. The failing checks have been fixed now.
Please take another look when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: nil pointer dereference in QueryServerVersion when dbVersion is nil

1 participant