Skip to content

Commit cc5a6bc

Browse files
committed
iteration 1
1 parent fe75494 commit cc5a6bc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public boolean preSampleRequest(final @Nonnull AppSecRequestContext ctx) {
9999
if (acquired) {
100100
log.debug("API security sampling is required for this request (presampled)");
101101
ctx.setKeepOpenForApiSecurityPostProcessing(true);
102+
// Update the map immediately to prevent race condition where multiple concurrent
103+
// requests see the same expired state before any of them updates the map
104+
updateApiAccessIfExpired(hash);
105+
log.info(
106+
"[APPSEC-57815] preSampleRequest updated accessMap immediately - route={}, hash={}",
107+
route,
108+
hash);
102109
return true;
103110
}
104111
return false;
@@ -115,7 +122,14 @@ public boolean sampleRequest(AppSecRequestContext ctx) {
115122
// This should never happen, it should have been short-circuited before.
116123
return false;
117124
}
118-
return updateApiAccessIfExpired(hash);
125+
// Note: With the race condition fix, the map was already updated by preSampleRequest()
126+
// when the semaphore was acquired. We just need to confirm the sampling decision.
127+
// No need to check expiration again since that would fail (we just updated it).
128+
log.info(
129+
"[APPSEC-57815] sampleRequest called - hash={}, route={}, returning true (map already updated in preSampleRequest)",
130+
hash,
131+
ctx.getRoute());
132+
return true;
119133
}
120134

121135
@Override

0 commit comments

Comments
 (0)