Skip to content

Conversation

@thomaspoignant
Copy link
Owner

@thomaspoignant thomaspoignant commented Oct 20, 2025

Description

This pull request fixes a critical bug in the /v1/allflags endpoint that was causing a 500 Internal Server Error due to a nil map assignment panic.

What was the problem?

The /v1/allflags endpoint was panicking with "assignment to entry in nil map" error when processing user requests that didn't include a custom field in the user or evaluation context. This occurred in the userRequestToUser() function at line 63 of cmd/relayproxy/controller/utils.go.

How it is resolved?

  • Added a nil check and initialization for the custom map in the userRequestToUser() function
  • If the custom field is nil, it's now properly initialized as an empty map before assignment
  • Added comprehensive test cases to cover both user context and evaluation context scenarios without custom fields

How can we test the change?

  • Added unit tests that verify the endpoint works correctly when user/evaluation contexts don't have custom fields
  • Tests cover both scenarios: user context without custom field and evaluation context without custom field
  • All existing tests continue to pass

Closes issue(s)

Resolve #4133

Checklist

  • I have tested this code
  • I have added unit test to cover this code
  • I have updated the documentation (README.md and /website/docs) - N/A for bug fix
  • I have followed the contributing guide

- Initialize custom map if nil in userRequestToUser function
- Add comprehensive test cases for user and evaluation contexts without custom fields
- Fixes issue #4133 where 500 error occurred due to nil map assignment

The panic was occurring when processing requests where the user or evaluation
context didn't include a 'custom' field, causing assignment to a nil map.
This fix ensures the custom map is properly initialized before use.
@thomaspoignant thomaspoignant self-assigned this Oct 20, 2025
@netlify
Copy link

netlify bot commented Oct 20, 2025

Deploy Preview for go-feature-flag-doc-preview ready!

Name Link
🔨 Latest commit a52d51f
🔍 Latest deploy log https://app.netlify.com/projects/go-feature-flag-doc-preview/deploys/68f71a056e02db000819ea54
😎 Deploy Preview https://deploy-preview-4134--go-feature-flag-doc-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.77%. Comparing base (fcdcf01) to head (a52d51f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4134   +/-   ##
=======================================
  Coverage   83.76%   83.77%           
=======================================
  Files         139      139           
  Lines        6831     6835    +4     
=======================================
+ Hits         5722     5726    +4     
  Misses        898      898           
  Partials      211      211           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link

@kodiakhq kodiakhq bot merged commit 7396246 into main Oct 21, 2025
24 checks passed
@kodiakhq kodiakhq bot deleted the fix-4133 branch October 21, 2025 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(bug) 500 Error when /v1/allflags is called for nil map assignment

2 participants