A JMeter thread's login sampler fails, yet it keeps running the checkout samplers. How do you stop that?
answer
- Continue is the default, so nothing stops
- One radio button abandons the iteration
- A scoped handler reacts to one sampler
- If Controller plus Flow Control Action for conditions
- The variable is JMeterThread.last_sample_ok
basics
~20 sThat is the default Continue policy. Set the Thread Group's error action to Start Next Thread Loop, or put a Flow Control Action under an If Controller so the stop fires only on the login.
solid answer
~50 sBy default a Thread Group's error action is `Continue`, so a failed login is recorded and the thread walks straight on to the next sampler. There are two JMeter answers. The blunt one is to set the group's **Action to be taken after a Sampler error** to `Start Next Thread Loop` — the thread abandons everything left in the current thread-group iteration and begins the next one. That is group-wide: *any* sampler failure will do it. The targeted one is to react only to the login. Put a **Result Status Action Handler** under the login sampler, or put an **If Controller** with the condition `${__jexl3(!${JMeterThread.last_sample_ok})}` after the login and place a **Flow Control Action** with `Action = Stop` and `Target = Current Thread` inside it — the bare `${JMeterThread.last_sample_ok}` is true when the sample *succeeded*, so a guard that fires on failure has to negate it. Either way the failed login row still reaches the results file; only what follows it is skipped.
code
xml · 13 lines<IfController guiclass="IfControllerPanel" testclass="IfController" testname="Only if login failed">
<stringProp name="IfController.condition">${__jexl3(!${JMeterThread.last_sample_ok})}</stringProp>
<boolProp name="IfController.evaluateAll">false</boolProp>
<boolProp name="IfController.useExpression">true</boolProp>
</IfController>
<hashTree>
<TestAction guiclass="TestActionGui" testclass="TestAction" testname="Stop this thread">
<intProp name="ActionProcessor.action">0</intProp>
<intProp name="ActionProcessor.target">0</intProp>
<stringProp name="ActionProcessor.duration"></stringProp>
</TestAction>
<hashTree/>
</hashTree>go deeper
Know that Continue is the default and that a failing sampler does not stop anything by itself. Be able to find the error-action panel on the Thread Group.
Explain what Start Next Thread Loop abandons, and how a Result Status Action Handler narrows the same reaction to one sampler's scope.
Show the diagnosis: read the results file, spot the cascade of dependent failures behind one real one, and pick the narrowest lever that fixes it.
Decide whether the guard belongs on the group, on the element, or as a visible conditional stop, and who has to be able to read it six months later.
## Why the thread carries on Nothing in JMeter couples one sampler's verdict to the next sampler's execution. The Thread Group's error field defaults to `Continue`, so after the login sample is recorded the thread simply asks its controller for the next sampler and runs it. With no session, the checkout requests fail as well, and the results file ends up with one failed login followed by a string of failed follow-ups per iteration — noise that hides the single real failure underneath it. JMeter gives you three levers, in ascending order of precision. ## Lever 1: the group-wide error action Set the Thread Group's **Action to be taken after a Sampler error** to `Start Next Thread Loop`. Internally this ends every loop on the path from the failing sampler back to the Thread Group and restarts the thread-group iteration, so the thread jumps straight to the top of its flow — back to the login. It is one radio button and it is honest about being coarse: it fires for *any* failing sampler in the group, not just the login. In the plan file it is a single value: ```xml <stringProp name="ThreadGroup.on_sample_error">startnextloop</stringProp> ``` ## Lever 2: a scoped handler on the login only Add a **Result Status Action Handler** under the login sampler and choose `Start Next Thread Loop` or `Stop Thread`. Now only that sampler's failure triggers the reaction; a flaky product-image request further down the flow is recorded and ignored, as it should be. This element also exposes `Go to the next iteration of Current Loop` and `Break Current Loop`, which the Thread Group panel does not offer — useful when the login sits inside a nested loop and you want to leave only that loop. ## Lever 3: an explicit conditional stop When the decision deserves to be visible in the tree, make it explicit: 1. after the login sampler, add an **If Controller** with `Interpret Condition as Variable Expression` checked and the condition `${__jexl3(!${JMeterThread.last_sample_ok})}` — the controller runs its children when the condition evaluates to `true`, and the bare `${JMeterThread.last_sample_ok}` is `true` when the sample *succeeded*, so it has to be negated; 2. inside it, add a **Flow Control Action** with `Action = Stop` and `Target = Current Thread`, or `Action = Start Next Thread Loop`; 3. leave the rest of the flow outside the controller. `JMeterThread.last_sample_ok` is the variable JMeter writes after every sample, holding `true` or `false`. The Flow Control Action is a sampler, but it produces no sample result of its own, so it adds no row to the results file. Its `Target` selector only applies to `Stop` and `Stop Now`; the loop actions always act on the current thread. ## Which lever to pull | Situation | Reach for | |---|---| | Any failure makes the rest of the iteration pointless | Thread Group set to `Start Next Thread Loop` | | Only one step is load-bearing for the rest of the flow | Result Status Action Handler under that sampler | | The condition is richer than “the sample failed” | If Controller plus Flow Control Action | | A broken login should abort the run before load starts | `Stop Test` on a setUp Thread Group | ## Two things that do not change - **The failed login is still recorded.** The error action is applied after the post-processors, assertions and listeners have run, so the row lands in the JTL with its real verdict. You lose the follow-ups, not the evidence. - **Nothing here retries.** None of these levers re-issues the login. JMeter ships no retry element and no per-sampler retry checkbox; what it offers is a way to stop wasting the iteration, not a way to have another go. A last practical note: whichever lever you pull, name the element for what it guards. `Start Next Thread Loop` chosen on a Thread Group is a single radio button three panels away from the sampler it protects, and the next person to open the plan will not go looking for it.
- What is the difference between Start Next Thread Loop and Go to the next iteration of Current Loop here?Start Next Thread Loop ends every loop between the failing sampler and the Thread Group, so the thread restarts its whole flow. Go to the next iteration of Current Loop ends only the innermost enclosing loop, leaving any outer loops and the rest of the iteration intact.
- Would the failed login still appear in the results file if you chose Stop Thread instead?Yes. The error action is applied only after the sample has been through its post-processors, assertions and listeners, so the failing row is written first. What disappears is every sampler the thread would have run after it.
- Why not simply have JMeter retry the login?There is no retry element to reach for. The only retry JMeter offers is the HTTP client's transport-level one, which will not re-issue a login that the server answered with a rejection. A repeat attempt has to be built as an explicit loop in the plan.
saying these in an interview costs you the question
- Expecting a failed sampler to halt the flow on its own
- Setting the group-wide action when only one step matters
- Believing the failed login row is lost when the thread stops
- Confusing the Flow Control Action with a retry mechanism
- Using Stop Test when only this thread should end