Skip to content

Commit a3a806e

Browse files
partoufclaude
andcommitted
Fix race condition in refreshCELibraries causing Go/Rust/Fortran libraries to be misclassified
The previous implementation wrapped all 4 HTTP requests in a single Promise and called resolve() in each response handler, so the promise resolved as soon as the first request (typically C++) completed. This meant allGoLibrariesAndVersions (and others) could still be null when refreshConanLibraries ran, causing Go libraries to fall through to the forceall fallback and be misclassified as C++. Use Promise.all to wait for all language API calls before proceeding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 30b844a commit a3a806e

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

index.js

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -161,50 +161,13 @@ async function refreshCECompilers() {
161161
});
162162
}
163163

164-
async function refreshCELibraries() {
164+
function fetchCELibraries(language) {
165165
return new Promise((resolve, reject) => {
166-
https.get(`${ceserverurl}/api/libraries/c++`, { headers: { Accept: 'application/json' } }, (resp) => {
167-
let data = '';
168-
resp.on('data', (chunk) => data += chunk);
169-
resp.on('end', () => {
170-
allCppLibrariesAndVersions = JSON.parse(data);
171-
resolve(true);
172-
});
173-
}).on('error', (err) => {
174-
console.error(err);
175-
reject(err);
176-
});
177-
178-
https.get(`${ceserverurl}/api/libraries/rust`, { headers: { Accept: 'application/json' } }, (resp) => {
166+
https.get(`${ceserverurl}/api/libraries/${language}`, { headers: { Accept: 'application/json' } }, (resp) => {
179167
let data = '';
180168
resp.on('data', (chunk) => data += chunk);
181169
resp.on('end', () => {
182-
allRustLibrariesAndVersions = JSON.parse(data);
183-
resolve(true);
184-
});
185-
}).on('error', (err) => {
186-
console.error(err);
187-
reject(err);
188-
});
189-
190-
https.get(`${ceserverurl}/api/libraries/fortran`, { headers: { Accept: 'application/json' } }, (resp) => {
191-
let data = '';
192-
resp.on('data', (chunk) => data += chunk);
193-
resp.on('end', () => {
194-
allFortranLibrariesAndVersions = JSON.parse(data);
195-
resolve(true);
196-
});
197-
}).on('error', (err) => {
198-
console.error(err);
199-
reject(err);
200-
});
201-
202-
https.get(`${ceserverurl}/api/libraries/go`, { headers: { Accept: 'application/json' } }, (resp) => {
203-
let data = '';
204-
resp.on('data', (chunk) => data += chunk);
205-
resp.on('end', () => {
206-
allGoLibrariesAndVersions = JSON.parse(data);
207-
resolve(true);
170+
resolve(JSON.parse(data));
208171
});
209172
}).on('error', (err) => {
210173
console.error(err);
@@ -213,6 +176,19 @@ async function refreshCELibraries() {
213176
});
214177
}
215178

179+
async function refreshCELibraries() {
180+
const [cpp, rust, fortran, go] = await Promise.all([
181+
fetchCELibraries('c++'),
182+
fetchCELibraries('rust'),
183+
fetchCELibraries('fortran'),
184+
fetchCELibraries('go'),
185+
]);
186+
allCppLibrariesAndVersions = cpp;
187+
allRustLibrariesAndVersions = rust;
188+
allFortranLibrariesAndVersions = fortran;
189+
allGoLibrariesAndVersions = go;
190+
}
191+
216192
function newProxy() {
217193
const proxy = httpProxy.createProxyServer({});
218194

0 commit comments

Comments
 (0)