-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fix config access due to race condition #1252
base: devel
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis pull request addresses a race condition in the configuration access by using a read-write lock to protect the global configuration. It also refactors the configuration loading and access logic into a separate file, and removes the logging macros from the main source file. Sequence diagram showing thread-safe configuration accesssequenceDiagram
participant T1 as Thread 1
participant T2 as Thread 2
participant CM as ConfigManager
participant C as Config
Note over CM: Using read-write lock for thread safety
T1->>CM: getConfigVal()
activate CM
CM->>CM: pthread_rwlock_rdlock()
CM->>C: Read config value
CM->>CM: pthread_rwlock_unlock()
CM-->>T1: Return value
deactivate CM
T2->>CM: setConfigVal()
activate CM
CM->>CM: pthread_rwlock_wrlock()
CM->>C: Write config value
CM->>CM: pthread_rwlock_unlock()
CM-->>T2: Return status
deactivate CM
Class diagram showing the new configuration and utility structureclassDiagram
class Config {
+char repo_id[MAX_ID_LEN]
+char server_addr[MAX_ADDR_LEN]
+char pub_key[MAX_KEY_LEN]
+char priv_key[MAX_KEY_LEN]
+char server_key[MAX_KEY_LEN]
+char user[MAX_ID_LEN]
+char test_path[MAX_PATH_LEN]
+char log_path[MAX_PATH_LEN]
+char globus_collection_path[MAX_PATH_LEN]
+size_t timeout
}
class ConfigManager {
-Config g_config
-bool config_loaded
-pthread_rwlock_t config_rwlock
+bool initializeGlobalConfig()
+void allowConfigReinitialization()
+bool getConfigVal(char* label, char* dest, size_t max_len)
+bool setConfigVal(char* label, char* src)
+Config createLocalConfigCopy()
}
class Util {
+void uuidToStr(unsigned char* uuid, char* out)
+bool decodeUUID(char* input, char* uuid)
}
class AuthzLog {
+FILE* log_file
+bool write_to_file
+void AUTHZ_LOG_DEBUG()
+void AUTHZ_LOG_INFO()
+void AUTHZ_LOG_ERROR()
+void AUTHZ_LOG_INIT()
+void AUTHZ_LOG_CLOSE()
}
ConfigManager --> Config : manages
note for ConfigManager "Thread-safe configuration management"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
@par-hermes format |
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.
Hey @JoshuaSBrown - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
I have a few comments about Config.c
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.
Questions about:
- Needing to use
pthread_rwlock_unlock
after aquiring the read lock withpthread_rwlock_rdlock
. - General C practices.
327bbd2
to
9f8b987
Compare
… file load function
This PR is going to be split up into smaller pieces and merged more piecemeal as it has expanded beyond the initial scope. |
PR Description
See issue for what triggered this PR #1241. The PR pulls out the Config structure a C struct with no safety mechanisms to prevent race conditions and memory corruption. The global config file is placed behind thread locks, in addition a switch is placed in front of initializing the Config structure to prevent excessive reads from the config file once the global state has been loaded into memory.
Tasks
Summary by Sourcery
Refactor config loading and access to prevent race conditions and improve thread safety.
Bug Fixes:
Enhancements:
Tests: