Fault Injection Engine
Configuring and executing deterministic network failures at precise byte boundaries.
Table of Contents
- Why Deterministic Faults?
- Fault Profile Structure
- Detailed Fault Types
- Creating Profiles in the Editor
Why Deterministic Faults?
Random network monkey testing can confirm that your game eventually handles errors, but it cannot reproduce the exact condition that caused a crash.
PatchProof’s Fault Injection Engine allows engineers to write deterministic rules:
- “Abort the connection on request #2 after exactly 65,536 bytes of
soundtrack.bundlehave streamed.” - “Inject a 404 status code when requesting any file matching
.*_scenes_.*\.bundle.” - “Corrupt 128 bytes starting at offset 1,024 to verify CRC rejection.”
These rules execute identically every single time, enabling automated regression prevention.
Fault Profile Structure
Defined in FaultProfile.cs:
[Serializable]
public class FaultProfile
{
public string name = "New Fault Profile";
public bool enabled = true;
public List<FaultRule> rules = new List<FaultRule>();
}
[Serializable]
public class FaultRule
{
public FaultType faultType;
public string urlPattern = ".*";
public long triggerAtByteOffset = 0;
public int corruptByteCount = 64;
public int delayMilliseconds = 0;
public int httpStatusCode = 500;
}
Detailed Fault Types
1. Connection Drop (FaultType.ConnectionDrop)
- Mechanism: Reads and transmits bytes from disk normally. When
totalBytesTransferred >= triggerAtByteOffset, the socket callsHttpListenerResponse.Abort(). - Client Experience: Unity Web Request throws
UnityWebRequestException: Request aborted / Connection reset by peer. - Expected Client Handling: Client retry loops should resume downloading from byte offset $N$ using HTTP
Rangeheaders, or restart the bundle download cleanly.
2. Timeout & Latency (FaultType.Timeout / LatencyDelay)
- Mechanism: Blocks the origin thread with
Thread.Sleep(delayMilliseconds)before sending response headers or streaming content. - Client Experience: Unity Web Request hangs until its internal
timeoutexpires. - Expected Client Handling: Client must catch
UnityWebRequest.Result.ConnectionErrorwith timeout description and trigger user-facing reconnect dialogs.
3. HTTP 404 Not Found (FaultType.NotFound404)
- Mechanism: Responds with
StatusCode = 404and empty content body. - Client Experience: Addressables runtime logs:
RemoteProviderException: Unable to load asset bundle from 404 URL. - Expected Client Handling: Critical updates must abort cleanly and notify the player of an incomplete rollout.
4. Payload Bit-Flipping (FaultType.CorruptPayload)
- Mechanism: As bytes stream through memory, PatchProof executes a bitwise XOR on
corruptByteCountbytes:buffer[i] = (byte)(buffer[i] ^ 0xFF); - Client Experience: The download finishes with 200 OK, but Addressables header parsing throws
CRC Mismatch: The downloaded bundle did not match the expected hash. - Expected Client Handling: Addressables must purge the corrupted bundle from
UnityEngine.Cachingand not attempt to load broken assets.
Creating Profiles in the Editor
- Open
Tools > PatchProof > Origin & Fault Profiles. - Click “Add Fault Profile”.
- Choose a template or create custom rules:
- Template: Mobile Subway Disconnect: Drops connection at 256 KB.
- Template: Incomplete CDN Edge: Injects 404 on all
.bundlefiles. - Template: High Latency Satellite: Injects 1,500 ms delay on all requests.
- Set the URL Pattern regex.
- Click “Save Fault Profile”. The profile is immediately available in the Rehearsal Room scenario dropdown.
Pro Tip: Testing Catalog Downgrades
Create a fault rule targeting
\.hash$files that returns a 304 Not Modified header or delayed response. This tests whether your game client gracefully handles scenarios where the remote CDN has not yet updated its primary hash file.