Skip to content

Commit edaa452

Browse files
committed
Ensure inflight state empty at end of test
If we push inflight state during the request and do not pop it on the response (or erroneously push inflight state for a request that does not have a response a la zero-ack produce), then we will leak memory. Signed-off-by: Robert Young <[email protected]>
1 parent 3a0cc26 commit edaa452

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

kroxylicious-filters/kroxylicious-authorization/src/main/java/io/kroxylicious/filter/authorization/AuthorizationFilter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package io.kroxylicious.filter.authorization;
99

1010
import java.util.ArrayList;
11+
import java.util.Collections;
1112
import java.util.EnumMap;
1213
import java.util.HashMap;
1314
import java.util.List;
@@ -273,4 +274,10 @@ public void adjustResponse(ApiVersionsResponseData response) {
273274
apiVersions.removeAll(toRemove);
274275

275276
}
277+
278+
@SuppressWarnings("java:S1452") // wildcard type expected
279+
@VisibleForTesting
280+
Map<Integer, InflightState<?>> inflightState() {
281+
return Collections.unmodifiableMap(inflightState);
282+
}
276283
}

kroxylicious-filters/kroxylicious-authorization/src/test/java/io/kroxylicious/filter/authorization/AuthorizationFilterTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ void authorization(ScenarioDefinition definition) {
148148
if (!mockUpstream.isFinished()) {
149149
throw new IllegalStateException("test has finished, but mock responses are still queued");
150150
}
151+
// we expect that any inflight state pushed during a request is always popped on the corresponding response
152+
// if it is non-empty then we may have a memory leak
153+
assertThat(authorizationFilter.inflightState())
154+
.describedAs("inflight state")
155+
.isEmpty();
151156
}
152157

153158
private static String toYaml(Object actualBody) {

0 commit comments

Comments
 (0)