Skip to content

Commit a49f1b2

Browse files
committed
remove unnecessary changes
1 parent 69a96c9 commit a49f1b2

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

dd-java-agent/appsec/src/main/java/com/datadog/appsec/api/security/AppSecSpanPostProcessor.java

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,20 @@ public AppSecSpanPostProcessor(ApiSecuritySampler sampler, EventProducerService
3131

3232
@Override
3333
public void process(@Nonnull AgentSpan span, @Nonnull BooleanSupplier timeoutCheck) {
34-
AppSecRequestContext ctx = null;
35-
RequestContext ctx_ = null;
36-
boolean needsRelease = false;
37-
38-
try {
39-
ctx_ = span.getRequestContext();
40-
if (ctx_ == null) {
41-
return;
42-
}
43-
ctx = ctx_.getData(RequestContextSlot.APPSEC);
44-
if (ctx == null) {
45-
return;
46-
}
34+
final RequestContext ctx_ = span.getRequestContext();
35+
if (ctx_ == null) {
36+
return;
37+
}
38+
final AppSecRequestContext ctx = ctx_.getData(RequestContextSlot.APPSEC);
39+
if (ctx == null) {
40+
return;
41+
}
4742

48-
// Check if we acquired a permit for this request - must be inside try to ensure finally runs
49-
needsRelease = ctx.isKeepOpenForApiSecurityPostProcessing();
50-
if (!needsRelease) {
51-
return;
52-
}
43+
if (!ctx.isKeepOpenForApiSecurityPostProcessing()) {
44+
return;
45+
}
5346

47+
try {
5448
if (timeoutCheck.getAsBoolean()) {
5549
log.debug("Timeout detected, skipping API security post-processing");
5650
return;
@@ -62,25 +56,21 @@ public void process(@Nonnull AgentSpan span, @Nonnull BooleanSupplier timeoutChe
6256
log.debug("Request sampled, processing API security post-processing");
6357
extractSchemas(ctx, ctx_.getTraceSegment());
6458
} finally {
65-
// Always release the semaphore permit if we acquired one
66-
if (needsRelease) {
67-
if (ctx != null) {
68-
ctx.setKeepOpenForApiSecurityPostProcessing(false);
69-
// XXX: Close the additive first. This is not strictly needed, but it'll prevent getting
70-
// it detected as a missed request-ended event.
71-
try {
72-
ctx.closeWafContext();
73-
} catch (Exception e) {
74-
log.debug("Error closing WAF context", e);
75-
}
76-
try {
77-
ctx.close();
78-
} catch (Exception e) {
79-
log.debug("Error closing AppSecRequestContext", e);
80-
}
81-
}
82-
sampler.releaseOne();
59+
ctx.setKeepOpenForApiSecurityPostProcessing(false);
60+
// XXX: Close the additive first. This is not strictly needed, but it'll prevent getting it
61+
// detected as a
62+
// missed request-ended event.
63+
try {
64+
ctx.closeWafContext();
65+
} catch (Exception e) {
66+
log.debug("Error closing WAF context", e);
67+
}
68+
try {
69+
ctx.close();
70+
} catch (Exception e) {
71+
log.debug("Error closing AppSecRequestContext", e);
8372
}
73+
sampler.releaseOne();
8474
}
8575
}
8676

0 commit comments

Comments
 (0)