-
Notifications
You must be signed in to change notification settings - Fork 385
fix threading, and performance issues across NVQIR and REST helpers #4510
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
ca5f825
356a3bc
17afa55
b2c3153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,8 +187,11 @@ void IQMServerHelper::initialize(BackendConfig config) { | |
| } else { | ||
| // Set alternative iqmclient-cli tokens file path if provided via env var | ||
| auto envTokenFilePath = getenv("IQM_TOKENS_FILE"); | ||
| // FIX(security): guard getenv("HOME") against nullptr (e.g. in containers) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for the FIX comments in the code.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| const char *homeDir = getenv("HOME"); | ||
| auto defaultTokensFilePath = | ||
| std::string(getenv("HOME")) + "/.cache/iqm-client-cli/tokens.json"; | ||
| homeDir ? std::string(homeDir) + "/.cache/iqm-client-cli/tokens.json" | ||
| : std::string(); | ||
| if (envTokenFilePath) { | ||
| tokensFilePath = std::string(envTokenFilePath); | ||
| } else if (cudaq::fileExists(defaultTokensFilePath)) { | ||
|
|
@@ -537,8 +540,9 @@ std::string IQMServerHelper::writeQuantumArchitectureFile(void) { | |
| fwrite(outputLine.c_str(), outputLine.length(), 1, file); | ||
| } | ||
|
|
||
| // FIX(bug): fclose() already closes the underlying fd from fdopen(). | ||
| // Calling close(fd) after fclose() is a double-close (UB). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, no need for comments.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| fclose(file); | ||
| close(fd); | ||
|
|
||
| return quantumArchitectureFilePath; | ||
| } // IQMServerHelper::writeQuantumArchitectureFile() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,8 +245,15 @@ static std::string searchAPIKey(std::string &key, std::string &refreshKey, | |
| hwConfig = std::string(creds); | ||
| else if (!userSpecifiedConfig.empty()) | ||
| hwConfig = userSpecifiedConfig; | ||
| else | ||
| hwConfig = std::string(getenv("HOME")) + std::string("/.quantinuum_config"); | ||
| else { | ||
| // FIX(security): guard getenv("HOME") against nullptr (e.g. in containers) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, no need for comments.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| const char *home = std::getenv("HOME"); | ||
| if (!home) | ||
| throw std::runtime_error( | ||
| "HOME environment variable is not set. Cannot locate Quantinuum " | ||
| "credentials file. Set CUDAQ_QUANTINUUM_CREDENTIALS to override."); | ||
| hwConfig = std::string(home) + std::string("/.quantinuum_config"); | ||
| } | ||
| if (cudaq::fileExists(hwConfig)) { | ||
| findApiKeyInFile(key, hwConfig, refreshKey, timeStr); | ||
| } else { | ||
|
|
@@ -705,7 +712,9 @@ void QuantinuumServerHelper::refreshTokens(bool force_refresh) { | |
| throw std::runtime_error( | ||
| "Cannot get refresh access token, refresh key is empty."); | ||
| } | ||
| std::mutex m; | ||
| // FIX(bug): mutex must be static to provide actual cross-thread protection. | ||
| // A local mutex is created/destroyed per call, giving zero synchronization. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, no need for comments.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| static std::mutex m; | ||
| std::lock_guard<std::mutex> l(m); | ||
| auto now = std::chrono::high_resolution_clock::now(); | ||
|
|
||
|
|
||
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.
Why is there whitepsace here?
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.
Done