Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example leakage error correction #3205

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

VolanDeVovan
Copy link

I already created issue
#3204

I tried to fix it and it seems to have solved the problem
But my solution is not very pretty
But I think it will be useful to you

Copy link

vercel bot commented Feb 5, 2025

Someone is attempting to deploy a commit to the umami-software Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR addresses a critical memory leak issue in Umami's geolocation functionality by modifying the MaxMind database initialization process.

  • Moved MaxMind database initialization outside getLocation function in src/lib/detect.ts to prevent repeated loading
  • Critical bug: Undefined result variable used in getLocation function needs to be defined
  • Missing error handling: No cleanup/close handling for MaxMind database on application shutdown
  • Potential race condition: initializeMaxmind() called but not awaited properly
  • Type safety issue: lookupPromise uses any type instead of proper MaxMind types

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

2 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

}

const result = lookup.get(ip);

if (result) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The result variable is referenced but never defined. Need to add const result = lookup.get(ip); before this line.

Suggested change
if (result) {
const result = lookup.get(ip);
if (result) {

let lookup;

// 1. Initialize lookup OUTSIDE any function, but make it a Promise.
let lookupPromise: any = null;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a more specific type than 'any' for lookupPromise, such as 'Promise<maxmind.Reader> | null'

return lookupPromise;
}

initializeMaxmind()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This initialization should be awaited and handled properly during application startup to prevent race conditions

@VolanDeVovan
Copy link
Author

is not the best solution because the process hangs(

Volodymyr Kravchenko added 3 commits February 6, 2025 00:33
@mikecao
Copy link
Collaborator

mikecao commented Feb 5, 2025

I don't understand how this is any different than the previous solution. The lookup variable is still a global.

@VolanDeVovan
Copy link
Author

I don't understand how this is any different than the previous solution. The lookup variable is still a global.

I updated the solution a bit and it tentatively works
Although I myself don't fully understand why this problem occurs

@mikecao
Copy link
Collaborator

mikecao commented Feb 5, 2025

Is it possible just updating the maxmind library fixes it?

@VolanDeVovan
Copy link
Author

VolanDeVovan commented Feb 5, 2025

Is it possible just updating the maxmind library fixes it?

It didn't work for me. But maybe I did something wrong

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.

2 participants