Skip to content

fix: Adjust recursive cycle detection to fix EXC_BAD_ACCESS#181

Merged
NeedleInAJayStack merged 1 commit into
GraphQLSwift:mainfrom
CaptureContext:main
May 14, 2026
Merged

fix: Adjust recursive cycle detection to fix EXC_BAD_ACCESS#181
NeedleInAJayStack merged 1 commit into
GraphQLSwift:mainfrom
CaptureContext:main

Conversation

@maximkrouk
Copy link
Copy Markdown
Contributor

@maximkrouk maximkrouk commented Apr 14, 2026

Prev implementation triggered EXC_BAD_ACCESS exception on line 711

fieldPathIndexByTypeName[inputObj.name] = fieldPath.count could not access count since fieldPath was <uninitialized> even tho it clearly was

This commit wraps this logic into a class so createInputObjectCircularRefsValidator function no longer mutably captures a value type

Note

I also added .editorconfig file, this will help potential contributors to avoid switching their default formatting to "4-spaces" while working on graphql package

Prev implementation triggered EXC_BAD_ACCESS exception on line 711

> `fieldPathIndexByTypeName[inputObj.name] = fieldPath.count` could not access `count` since `fieldPath` was `<uninitialized>` even tho it clearly was

This commit wraps this logic into a class so `createInputObjectCircularRefsValidator` function no longer mutably captures a value type
}

visitedTypes.insert(inputObj)
fieldPathIndexByTypeName[inputObj.name] = fieldPath.count
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exception was raised here on fieldPath.count access, for some reason it was only reproducible in release builds, debug ones worked fine 💁‍♂️

@maximkrouk maximkrouk changed the title fix: Adjust recursive cycle detection fix: Adjust recursive cycle detection to fix EXC_BAD_ACCESS Apr 14, 2026
@NeedleInAJayStack
Copy link
Copy Markdown
Member

NeedleInAJayStack commented Apr 21, 2026

Thanks for the PR! Out of curiosity, in which version of Swift were you experiencing the issue?

@NeedleInAJayStack NeedleInAJayStack self-assigned this Apr 21, 2026
@maximkrouk
Copy link
Copy Markdown
Contributor Author

Thanks for the PR! Out of curiosity, in which version of Swift were you experiencing the issue?

I believe it was the latest one (seems to be 4.1.0), probably the issue might also be environment-related maybe specific swift versions work fine with it, but I managed to reproduce it both in local macos release build and linux build in docker container

From my Dockerfile:

ARG SWIFT_IMAGE=swift:6.3
ARG SWIFT_RUNTIME_IMAGE=swift:6.3-slim

From my local env (Xcode 26.4 Beta (17E5159k)):

swift --version
swift-driver version: 1.148.6 Apple Swift version 6.3 (swiftlang-6.3.0.119.2 clang-2100.0.119.1)
Target: arm64-apple-macosx26.0

@NeedleInAJayStack
Copy link
Copy Markdown
Member

Hey, sorry about the delay. I'm also able to recreate this on Swift 6.3 in release mode, and I've validated that the fix works. It's kinda strange that it works - this seems like a bug with closure variable capture with the compiler, so I may raise it up to the Swift team as well.

I'm going to go ahead and merge this.

Thanks for contributing!

@NeedleInAJayStack NeedleInAJayStack merged commit 17c68cf into GraphQLSwift:main May 14, 2026
9 checks passed
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.

2 participants