Repository navigation
fix(pii): bound custom-pattern matching time per request - #9584
Merged
Merged
Conversation
Presidio's REGEX_TIMEOUT_SECONDS bounds one custom pattern on one text, so a batch request could cost texts x patterns x that timeout (2,000 texts x 20 patterns x 2s) on a single handler thread. Charge every custom-pattern match to a per-request 60s budget and reject the request with a 400 once it is spent.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryAdds a shared 60-second budget for custom-pattern matching within each PII request.
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
REGEX_TIMEOUT_SECONDS(2s) bounds one custom pattern on one text, so a single batch request could costtexts x patterns x 2s(2,000 texts x 20 patterns = ~22h on one handler thread). A pathological pattern like(a|aa)+$hits the per-match cap on every text, and the sync handler thread keeps running after the client gives up, so each retry ties up another threadPiiServiceRejectedError→ route 422 → no retry inmask-client, and it isn't treated as an outage, so the chunk fails closed without retry amplificationvalidate-regex.tsTSDoc that named Presidio's timeout as the only boundType of Change
Testing
Drove
apps/pii/server.pywith the pinned Presidio 2.2.362 / spaCy 3.8.14 / FastAPI stack through FastAPI TestClient (en_core_web_smin place of the 5 large models), pre-fix vs post-fix:(a|aa)+$patterns, timeout 2s): post-fix/redact_batch(regex-only and full NLP paths) and/analyze_batchall return 400 in 60.4-63.0s/redactand/analyzestill return 200 after one ~2s timeout, same as beforePYTHONHASHSEEDon 6 seeds. The only run-to-run variation is the winner of exact equal-score span ties, which varies by seed on the unmodified server too (Presidio dedups viaset())biome checkon the TS file; JS gates otherwise left to CI (the diff is Python + one TSDoc sentence)Checklist
test-auditauthoring gate)