-
Notifications
You must be signed in to change notification settings - Fork 187
Upgrade to meshery/[email protected] #906
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
Conversation
Signed-off-by: Mericio <[email protected]>
Summary of ChangesHello @leecalcote, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily focuses on updating a core dependency, Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request upgrades meshery/schemas and introduces changes to the logging file handling. The dependency upgrade and the related constant renames are correct. The improvements to the logger to handle file leaks are a good step. However, the introduction of package-level file handles for logs is not thread-safe and can lead to resource leaks if SetLogger is called multiple times. I've added comments with suggestions to introduce a mutex to protect the shared state and prevent these issues.
| // logFile and errorLogFile are the file handles for the log files | ||
| // They are stored at package level to allow proper cleanup | ||
| logFile *os.File | ||
| errorLogFile *os.File |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing logFile and errorLogFile as package-level variables creates shared state. To prevent race conditions from concurrent access by SetLogger (in model.go) and CloseLogger, you should protect these variables with a sync.Mutex.
// logFile and errorLogFile are the file handles for the log files
// They are stored at package level to allow proper cleanup
logFile *os.File
errorLogFile *os.File
logMutex sync.Mutex| func CloseLogger() { | ||
| if logFile != nil { | ||
| _ = logFile.Close() | ||
| logFile = nil | ||
| } | ||
| if errorLogFile != nil { | ||
| _ = errorLogFile.Close() | ||
| errorLogFile = nil | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure thread safety when closing the log files, you should lock the mutex that protects logFile and errorLogFile.
Additionally, SetLogger in registry/model.go should also be updated to use this mutex and to close any previously opened file handles to prevent resource leaks if it's called multiple times.
Example for SetLogger:
func SetLogger(ismultiWriter bool) error {
logMutex.Lock()
defer logMutex.Unlock()
if logFile != nil {
_ = logFile.Close()
}
if errorLogFile != nil {
_ = errorLogFile.Close()
}
// ... rest of the function
}func CloseLogger() {
logMutex.Lock()
defer logMutex.Unlock()
if logFile != nil {
_ = logFile.Close()
logFile = nil
}
if errorLogFile != nil {
_ = errorLogFile.Close()
errorLogFile = nil
}
}
Signed-off-by: Mericio [email protected]