Blog

How to reproduce a random network error in your app

Your app crashed on a slow network, and on the next try everything works. You can’t fix a random error until you can repeat it, and you can’t prove the fix worked. Chaos in Microkoi Bench is random but repeatable: any run can be started again with the same failures on the same requests. Below is the step-by-step path from a crash to a verified fix.

Why a random error doesn’t repeat

Chaos picks failures at random: which request to delay, which to drop, which status to answer with. If the randomness started over every time chaos was turned on, a crash on the third product page request would stay a one-off. A developer would turn on the same profile and get different failures on different requests.

That’s why in Bench a failure depends on three things only: the run, the rule and the request number for that rule. The third request to the product page rule gets the same failure in a replayed run, no matter how many requests go to other rules or in what order.

A run: what it is and where to see it

Every time you turn chaos on, a run starts. While chaos is on, the run line is shown under the “Apply chaos” switch in the “Chaos” window:

The run line in the “Chaos” window
Run since 2:32 PM · 23 requests · 4 affected

That’s when the run started, how many requests matched the rules and how many of them chaos touched. The numbers update on their own. The time follows the format of the interface language.

Every exchange touched by chaos has an orange lightning bolt in the first column of the “Traffic” table. In that exchange’s panel, above the request or the response, there is a chaos line with the same bolt. It names the run and the request number: “Run 2:32 PM, request 3”. That’s the third request to the rule in the run started at 2:32 PM.

Step 1. It crashed — start the run over

Take a marketplace app. The “Unstable catalog” profile is on, with a rule for product pages, and the app crashed on the third product page you opened.

  1. In “Traffic”, open the exchange where the app crashed. The bolt in the first column makes it easy to find, and “Chaos” in the “Show only” group of “Filters” hides all other exchanges. Read the run and request number in the chaos line above the response, for example “Run 2:32 PM, request 3”.
  2. Open the “Chaos” window and click “Start over” next to the run line. Request counters restart at 1, and chaos stays on.
  3. Restart the app and repeat the same actions: open the catalog and three product pages in a row.

The third request to the product page rule gets the same failure, and the app crashes the same way. Repeat exactly the same actions: if the app sends an extra request to the same rule, such as a prefetch, the numbers shift.

Step 2. Hand the run to a developer

  1. Open the “Chaos” window and click the run line. The “Runs” list opens, newest first.
  2. Click “Copy code” on the run you need. The clipboard now holds an eight-character code of letters and digits, like K7Q2-9F3M.
  3. Paste the code into the bug report along with the profile and the steps.
A bug report with a chaos run
Screen: product page, app crash
Chaos profile: Unstable catalog
Run code: K7Q2-9F3M
Steps: open the catalog, open 3 product pages in a row
Crashes on: GET /v1/products/{id}, request 3
Failure: cut body, Bench cut the response
  1. The developer picks the “Unstable catalog” profile in the “Chaos” window.
  2. They open “Runs”, click “Replay from code…”, paste the code into the “Run code” field and click “Replay” or press Enter. Case, spaces and the hyphen don’t matter.
  3. They repeat the steps from the report and see the crash on the same request.

The code doesn’t include the profile: the run uses the profile selected in the window. The hint under the “Run code” field reminds you which one. Profiles live in the workspace’s chaos/ folder and go to git, so a teammate with the same workspace has the same profile.

Step 3. Check the fix with the same run

A fix is checked not with a new random run but with the very same one. The same failures arrive, and this time the app has to handle them.

Replay fromWhat to clickWhen it fits
The “Chaos” window“Start over”The run is in progress
The “Runs” list“Replay” on the runThe run is from yesterday
The exchange panel“Replay run”The failed exchange is at hand
A code from a teammate“Replay from code…”The run is from another computer

“Replay run” in the chaos line of the exchange panel makes that exchange’s profile active, turns chaos on and starts the exchange’s run from request 1. The button works even for a run that is no longer in the list.

A replay doesn’t create a new entry: the run moves to the top of the list under the same name. Editing rules doesn’t break a run: a rule repeats its failures with the new settings. A rule deleted and created again counts requests from zero.

Mock server runs

Each mock server with chaos on has its own run. The “⋯” menu in the server’s chaos row has “Start over” and “Runs…”: the second item opens the same list, where the server’s runs are labeled with its name. “Replay” on such a run sets the server’s profile and turns on chaos for the server. The request number is shown in the bolt’s tooltip in the server’s request log.

Good to know up front

  • Bench keeps the last 50 runs of a workspace on this computer. The history doesn’t go to git, so you hand a teammate the code.
  • If a run’s profile is deleted, it shows “Profile deleted”, and the “Replay” button is unavailable.
  • Turning chaos on again or switching profiles starts a new run with new failures.

How to build your first profile and what the icons in the first “Traffic” column mean is covered in “Chaos engineering for a mobile app: where to start”.

Find an error in the beta that “couldn’t be reproduced” before, and write to beta@microkoi.com about whether a run repeated it and what the bug report was missing. We read every email.

Microkoi BenchChaosDelays, errors and a slow network

Try it on your own project

The beta is free and needs no sign-up. Download it, pick your project folder and start the proxy — your first requests will show up within minutes.

Version 0.9.6 · macOS, Windows and Linux · no sign-up