Skip to content

fix(resolve): fix mutation-during-iteration bug in optionallyAllowCustomExtensionProperties#1402

Merged
jensneuse merged 1 commit intomasterfrom
jensneuse/fix-nil-object-visit
Feb 21, 2026
Merged

fix(resolve): fix mutation-during-iteration bug in optionallyAllowCustomExtensionProperties#1402
jensneuse merged 1 commit intomasterfrom
jensneuse/fix-nil-object-visit

Conversation

@jensneuse
Copy link
Copy Markdown
Member

@jensneuse jensneuse commented Feb 20, 2026

Summary

Fix SIGSEGV (segmentation violation at addr=0x8) caused by deleting Object.kvs entries while Visit() iterates over them. This occurred in optionallyAllowCustomExtensionProperties when filtering extension fields.

Changes

  • Replaced mutation-during-iteration pattern with object reconstruction: instead of deleting disallowed keys inside the Visit callback, rebuild extensions with only allowed keys
  • Simplified optionallyOmitErrorExtensions by removing redundant Exists() check before Del() (Del is a safe no-op on missing keys)
  • Added 3 comprehensive tests providing 100% coverage of the fixed function

Test Coverage

All tests pass, including 3 new tests covering previously uncovered branches:

  • Multiple non-allowed field deletions (the crash scenario)
  • Non-object extension types being preserved
  • Allowed fields configured but none present in extensions

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Error responses now properly handle extension field filtering, removing disallowed fields and preserving allowed ones.
    • Fixed edge cases with null extension values and missing allowed fields.
  • Tests

    • Added test coverage for extension field handling in error responses.

…tomExtensionProperties

Prevent SIGSEGV (signal SIGSEGV: segmentation violation code=0x2 addr=0x8)
caused by deleting Object.kvs entries while Visit() iterates over them.
Instead of calling Del() in the Visit callback, rebuild the extensions
object with only allowed keys. This approach is also zero-allocation
when iterating allowedErrorExtensionFields.

Also simplify optionallyOmitErrorExtensions by removing redundant Exists()
check before Del() since Del() is a safe no-op on missing keys.

- Add 3 new tests providing 100% coverage of optionallyAllowCustomExtensionProperties
- Verify existing tests pass

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 20, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

This PR refactors error extension field handling in the GraphQL engine's loader component. It changes the extension filtering logic to either completely remove the extensions object when no fields are allowed or construct a new filtered extensions object with only permitted fields, replacing the previous in-place modification approach.

Changes

Cohort / File(s) Summary
Error Extension Filtering Logic
v2/pkg/engine/resolve/loader.go
Refactored optionallyAllowCustomExtensionProperties to replace in-place filtering with constructing a new extensions object or removing it entirely. Simplified optionallyOmitErrorExtensions to unconditionally delete extensions when feature flag is enabled.
Extension Handling Tests
v2/pkg/engine/resolve/loader_hooks_test.go
Added three test cases validating extension field filtering behavior: removal of non-allowed fields, preservation of null extensions, and complete removal when no allowed fields match.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • graphql-go-tools#1217: Modifies error extension handling in the same loader component with complementary changes to extension filtering and flag-based behavior control.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: fixing a mutation-during-iteration bug in optionallyAllowCustomExtensionProperties, which is the primary problem addressed in this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jensneuse/fix-nil-object-visit

Comment @coderabbitai help to get the list of available commands and usage tips.

jensneuse added a commit to wundergraph/cosmo that referenced this pull request Feb 20, 2026
Fix mutation-during-iteration SIGSEGV in optionallyAllowCustomExtensionProperties.

Upstream PR: wundergraph/graphql-go-tools#1402

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jensneuse jensneuse merged commit 4c4bfc8 into master Feb 21, 2026
11 checks passed
@jensneuse jensneuse deleted the jensneuse/fix-nil-object-visit branch February 21, 2026 07:51
jensneuse pushed a commit that referenced this pull request Feb 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.0.0-rc.255](v2.0.0-rc.254...v2.0.0-rc.255)
(2026-02-21)


### Bug Fixes

* **resolve:** fix mutation-during-iteration bug in
optionallyAllowCustomExtensionProperties
([#1402](#1402))
([4c4bfc8](4c4bfc8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Bug Fixes
* Fixed a mutation-during-iteration bug in v2.0.0-rc.255

## Chores
* Updated release version

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants