A JMeter sampler has two HTTP Cookie Managers in scope after a plan merge. Which one applies?
answer
- Managers are not merged like Defaults
- The manual admits the choice is unspecified
- Each manager keeps its own storage area
- Look for superseded by in the log
basics
~20 sExactly one is used, and JMeter offers no way to say which. Cookie Managers are not merged the way Header Managers are, and a cookie stored in one is invisible to the other, so a thread's session can split unpredictably.
solid answer
~50 sThe scoping rules single this out: if more than one Manager is in the scope of a sampler, only one Manager is used, and there is currently no way to specify which. The HTTP Cookie Manager page repeats it and adds the part that actually bites — a cookie stored in one Cookie Manager is not available to any other manager, so the loser's cookie jar simply does not travel. The practical shape is a plan where login succeeds, the session cookie lands in one manager, and a later request in a different branch behaves as though it were never authenticated. The same "only one is used" rule holds for the HTTP Authorization Manager. The fix is structural, not a setting: make sure each sampler has exactly one Cookie Manager on its path to the Test Plan, usually by keeping a single one directly under the Thread Group.
code
text · 6 linesThread Group
├─ HTTP Cookie Manager "Global cookies"
├─ HTTP Request "Login"
└─ Simple Controller "Checkout flow"
├─ HTTP Cookie Manager "Checkout cookies" <- second one in scope
└─ HTTP Request "Place order" <- one manager used, which is unspecifiedgo deeper
Know that a Cookie Manager applies to every sampler under its parent, and that having more than one on a sampler's path is a mistake rather than a way to layer settings.
Explain the difference from Defaults: Manager elements are not merged, only one is used, and each manager holds its own cookie storage, so the loser's cookies never travel.
Show the diagnosis: the superseded warning in the log, counting managers on the failing sampler's path, and the reason the run still looks green because the status code stays healthy.
Make one Cookie Manager per Thread Group a reviewable standard, and require reusable fragments to carry no session managers of their own so composition cannot introduce a second.
## Why two of them ends up in a plan Nobody adds two Cookie Managers on purpose. They arrive by scope. A Test Fragment or a copied flow brings its own Cookie Manager, and it is pasted under a controller inside a Thread Group that already has one at the top. Or two plans are merged and each contributed a manager at a different depth. Both are now on the path from the sampler up to the Test Plan, so both are in scope, and the sampler has no way of telling you that. ## What the engine does with them JMeter's scoping rules state that the Header Manager, Cookie Manager and Authorization Manager are treated differently from the Configuration Defaults elements: the settings from Defaults are merged into a set of values that the sampler can see, but the settings from the Managers are **not** merged. If more than one Manager is in scope, only one Manager is used, and the manual is candid that there is currently no way to specify which. The HTTP sampler's own behaviour matches. As it is handed each config element in scope it sets the Cookie Manager, and when one is already present it logs a warning of the form `Existing CookieManager <name> superseded by <name>` at WARN level before replacing it. That log line is the single best diagnostic here: it names both elements, so you can find them in the tree without guessing. ## Why it hurts more than "one of them is ignored" If the two managers were interchangeable the loss would be cosmetic. They are not. Each Cookie Manager owns its own cookie storage area, and the component reference warns explicitly that a cookie stored in one cookie manager is not available to any other manager. So the sequence that breaks is: 1. The login sampler runs in a branch where manager A is the one used, and the session cookie is stored in A. 2. A later sampler sits where manager B is the one used. 3. B has never seen that cookie, so the request goes out unauthenticated. 4. The server answers with a login page rather than the resource, so the damage surfaces at a sampler far from the one that caused it. The result reads as an intermittent authentication defect in the system under test, when the cause is two elements sharing one sampler's scope. ## How to find it - **Grep the log.** Search `jmeter.log` for `superseded by`. Each hit names the pair of elements involved. - **Trace the path.** For a failing sampler, walk from it up to the Test Plan and count Cookie Managers. Anything above one is the bug. - **Search the .jmx.** Count `CookieManager` elements in the file, then look at which `hashTree` each sits in. - **Look at the response, not the status code.** The failure mode returns a healthy status with the wrong body, so the sampler shows green unless an assertion checks content. ## How to fix it The rule to converge on is one Cookie Manager per Thread Group, attached directly under the Thread Group, and none anywhere else on that path. If two different populations genuinely need separate cookie jars, give them separate Thread Groups rather than nested managers — that keeps each sampler in the scope of exactly one manager and makes the boundary visible in the tree. When a reusable fragment carries its own manager, strip it and rely on the group's. The same discipline applies to the HTTP Authorization Manager, whose page carries the identical note that with more than one in scope there is no way to specify which is used. ## The contrast worth holding in your head | Element | Two in one sampler's scope | | --- | --- | | HTTP Request Defaults | values are merged into one set the sampler can see | | HTTP Header Manager | entries are merged into one header list | | HTTP Cookie Manager | one is used; which one is unspecified | | HTTP Authorization Manager | one is used; which one is unspecified | Two of those four compose and two do not, and the two that do not are precisely the ones carrying per-thread session state. That is why the failure is silent: nothing is dropped loudly, a whole cookie jar is simply not the one in play.
- The run is green but a downstream request behaves as though the thread never logged in. How do you confirm this is the cause?Search jmeter.log for the warning that names one manager as superseded by another, then count Cookie Managers on the failing sampler's path to the Test Plan. Confirm the symptom by asserting on the response body rather than the status code, since the unauthenticated request usually returns a healthy status with a login page.
- Two populations in one plan genuinely need separate cookie jars. How would you structure that?Give each population its own Thread Group with exactly one Cookie Manager directly beneath it. That keeps every sampler in the scope of a single manager and makes the boundary visible in the tree, instead of relying on nested managers whose selection JMeter does not define.
- Does the same rule apply to the HTTP Authorization Manager?Yes. Its component page carries the same note: if more than one Authorization Manager is in the scope of a sampler there is no way to specify which one is used. Treat both as elements that must appear exactly once on any sampler's path.
saying these in an interview costs you the question
- Says the two Cookie Managers merge their cookie jars
- Claims the nearest Cookie Manager reliably wins
- Expects the plan to fail loudly when two are in scope
- Trusts a green status code as proof the session was sent
- Adds a third manager to force the behaviour they want