fix: validate non-empty flag key and non-null defaultValue in Variable<T>#202
Open
jonathannorris wants to merge 2 commits into
Open
fix: validate non-empty flag key and non-null defaultValue in Variable<T>#202jonathannorris wants to merge 2 commits into
jonathannorris wants to merge 2 commits into
Conversation
…e<T>
Match the existing guards in the Cloud client and the Java/Python SDKs.
Empty/null keys reaching the WASM bucketing engine trigger an internal
abort() at eventQueue.ts:122 ('Event missing target to save aggregate
event') which compiles to a wasmtime trap. After enough traps the AS
heap state becomes corrupted, and on the .NET host wasmtime panics
internally.
586ae5d to
6fc377b
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds fail-fast input validation to the Local client’s Variable<T>/VariableAsync<T> APIs to prevent null/empty flag keys (and null defaultValue) from reaching the WASM bucketing engine, aligning Local behavior with the existing Cloud client guards.
Changes:
- Added
ArgumentExceptionguard for null/emptykeyandArgumentNullExceptionguard for nulldefaultValueinDevCycleLocalClient.Variable<T>andVariableAsync<T>. - Added MSTest coverage for null/empty key for both sync/async paths, plus a sync-path null
defaultValuetest. - Normalized
using System;line (removed prior BOM/formatting artifact) in the test file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs |
Adds key/defaultValue validation to Local Variable and VariableAsync to prevent invalid inputs reaching WASM. |
DevCycle.SDK.Server.Local.MSTests/DevCycleTest.cs |
Adds tests for null/empty key behavior and null defaultValue behavior (sync path). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
keyanddefaultValueat the top of bothVariable<T>andVariableAsync<T>in the local clientArgumentExceptionfor null/emptykey,ArgumentNullExceptionfor nulldefaultValueDevCycleCloudClient.cs:101-109) and the Java/Python SDKsMotivation
When a null/empty flag key reaches the WASM bucketing engine, the empty
targetfalls through toeventQueue.ts:122and triggersthrow new Error('Event missing target to save aggregate event'). AssemblyScript compiles that throw toabort() + unreachable, which wasmtime catches and rethrows asLocalBucketingException.The trap unwinds without running AS's normal cleanup, leaving objects allocated in the trapped frame stranded in WASM linear memory. After enough traps the AS heap state corrupts, and on the .NET host the wasmtime Rust runtime eventually panics internally with a stack-pointer assertion in
traphandlers/backtrace.rs:250.Cross-SDK comparison shows .NET is the only host without this guard:
ArgumentException)IllegalArgumentException)ValueError)Behaviour change
Previously
Variable(user, "", defaultValue)returned a defaultedVariable<T>after logging a WASM error. Now it throwsArgumentExceptionimmediately. Same for null key, andArgumentNullExceptionfor nulldefaultValue. This matches the behaviour of every other entry point.Tests
5 new tests in
DevCycleTest.cs:Variable_NullKey_ThrowsArgumentExceptionVariable_EmptyKey_ThrowsArgumentExceptionVariableAsync_NullKey_ThrowsArgumentExceptionVariableAsync_EmptyKey_ThrowsArgumentExceptionVariable_NullDefaultValue_ThrowsArgumentNullExceptionAll 57 existing tests still pass.