Skip to content

Fix: In-memory route cache grows unbounded#133

Open
Xenon010101 wants to merge 4 commits into
madanrajsagar:mainfrom
Xenon010101:fix/bug-59-cache-size-limit
Open

Fix: In-memory route cache grows unbounded#133
Xenon010101 wants to merge 4 commits into
madanrajsagar:mainfrom
Xenon010101:fix/bug-59-cache-size-limit

Conversation

@Xenon010101

Copy link
Copy Markdown

Closes #59

Root cause: recentRouteCache and recentGeocodeCache in backend/routes/journey.js:23-24 were plain Maps with TTL expiration but no maximum size limit. Under heavy load they could grow unbounded, causing memory exhaustion.

Fix: Added MAX_CACHE_SIZE = 500 limit with LRU eviction — when a cache exceeds 500 entries, the oldest entry (first key in insertion order) is deleted before inserting the new one.

Closes madanrajsagar#129

Added verifyToken middleware to /send-email endpoint so that
emergency SOS emails can only be sent by authenticated users.

Previously anyone could POST to /send-email and trigger emergency
alerts to contacts, enabling spam and alert fatigue attacks.

Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
…nting

Closes madanrajsagar#70, Closes madanrajsagar#126

- Reduced express.json body limit from 8mb to 1mb (8mb was excessive
  for most endpoints and increased abuse potential)
- Removed duplicate app.use(userVideoRoutes) which caused redundant
  middleware execution and potential double-prefixing issues

Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
Closes madanrajsagar#62

Added isValidIncidentId check (non-empty string, max 64 chars) with
Express router.param middleware so all /:incidentId routes reject
malformed IDs with a clean 400 response instead of processing them.

Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
Closes madanrajsagar#59

Added MAX_CACHE_SIZE (500 entries) limit to both recentRouteCache and
recentGeocodeCache with LRU eviction (deletes oldest entry when full)
to prevent unbounded memory growth under heavy load.

Signed-off-by: Xenon010101 <xenon010101@users.noreply.github.com>
@Xenon010101

Copy link
Copy Markdown
Author

👋 Hi maintainer! Quick follow-up on this PR. It's been about a week — would appreciate a review when you get a chance. Happy to make any adjustments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

in-memory route cache grows unbounded

1 participant