fix(online): thread-safe fileMap with TTL cleanup, SLF4J logging, and Content-Length header#24011
Merged
wing328 merged 7 commits intoJun 28, 2026
Conversation
Contributor
There was a problem hiding this comment.
2 issues found across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
There was a problem hiding this comment.
2 issues found across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Contributor
There was a problem hiding this comment.
1 issue found across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
There was a problem hiding this comment.
2 issues found across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Member
|
thanks for the contribution to improve the openapi generator web services. let's give it a try |
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.
What changed?
HashMapwithConcurrentHashMaptoprevent data races under concurrent requests. Added a
@Scheduledcleanup task (runs every hour) that evictsentries older than 24 hours and deletes their associated temp files. Without this, the map and temp files on disk
grew unbounded for the lifetime of the server — a memory and disk leak on any long-running instance. Added
null-check guard in downloadFile so expired/missing entries return a clean
404 NOT_FOUNDwith message "File notfound or has expired" instead of an
NPE.System.out.printlnwithSLF4J logger: AllSystem.out.printlncalls in GenApiService replaced withLOGGER.debug/warn,consistent with the rest of the codebase.Content-Lengthheader to download response: The header was commented out indownloadFile(). SinceByteArrayResourceholds the full content in memory, the size is always known — wired in via.contentLength(resource.contentLength()).Why?
HashMapunder concurrent requests can corrupt state or silently lose entries.System.out.printlnbypasses the logging framework, making log levels and destinations uncontrollable.Content-Lengthbreaks clients that rely on it for progress bars or payload validation.Breaking changes?
None. Generated links are valid for 24 hours. If a user requests a download after expiry, they receive a 404 with
a descriptive message.
Tests added:
fileMapIsConcurrentHashMap— asserts map type via reflection.cleanExpiredFilesRemovesOldEntries— verifies TTL eviction (entry set 25h in the past).downloadExpiredFileReturns404— asserts clean 404 for missing/expired file IDs.concurrentGenerationDoesNotLoseEntries— 5 concurrent threads, all get unique codes.downloadHasContentLengthHeader— asserts Content-Length is present and > 0.Suggestion for follow-up:
Currently the API response (
ResponseCode) does not communicate the expiry window to callers. Consider adding anexpiresIn field to the response:
This would make the time-limited nature of the link explicit to API consumers without requiring them to read the
documentation.
Thanks for the the review and feedback
Summary by cubic
Enforces a 24h TTL for generated downloads with hourly cleanup, switches to
SLF4Jlogging, and adds the Content-Length header. Uses a thread-safe file map and retains entries if temp dir deletion fails so cleanup can retry; missing/expired links now return 404.Bug Fixes
HashMapwithConcurrentHashMapand added hourly@Scheduledcleanup that evicts >24h entries and deletes temp dirs; retain entry when deletion fails to retry later.downloadFile; missing/expired file IDs return 404 "File not found or has expired".contentLength(resource.contentLength())so downloads include the Content-Length header.petstore.jsonfor eviction/retention/recent entries/404s/concurrency, plus a controller test for Content-Length.Refactors
System.out.printlncalls toSLF4Jlogger.createdAtonGenerated(defaults to now) to support TTL checks.Written for commit 53abb23. Summary will update on new commits.