Skip to content

Commit 0ac7f5a

Browse files
committed
fix: prevent extension from hanging when embedder service is unavailable
- Made CodeIndexManager initialization non-blocking during extension activation - Added 5-second timeout to embedder validation to prevent indefinite hanging - Extension now loads successfully even if embedder service is missing Fixes #8777
1 parent 026cbd5 commit 0ac7f5a

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/extension.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function activate(context: vscode.ExtensionContext) {
100100
const contextProxy = await ContextProxy.getInstance(context)
101101

102102
// Initialize code index managers for all workspace folders.
103+
// Make initialization non-blocking to prevent extension activation from hanging
103104
const codeIndexManagers: CodeIndexManager[] = []
104105

105106
if (vscode.workspace.workspaceFolders) {
@@ -108,16 +109,15 @@ export async function activate(context: vscode.ExtensionContext) {
108109

109110
if (manager) {
110111
codeIndexManagers.push(manager)
112+
context.subscriptions.push(manager)
111113

112-
try {
113-
await manager.initialize(contextProxy)
114-
} catch (error) {
114+
// Initialize in the background without blocking extension activation
115+
// This prevents the extension from getting stuck if the embedder service is unavailable
116+
manager.initialize(contextProxy).catch((error) => {
115117
outputChannel.appendLine(
116118
`[CodeIndexManager] Error during background CodeIndexManager configuration/indexing for ${folder.uri.fsPath}: ${error.message || error}`,
117119
)
118-
}
119-
120-
context.subscriptions.push(manager)
120+
})
121121
}
122122
}
123123
}

src/services/code-index/service-factory.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,23 @@ export class CodeIndexServiceFactory {
9393
*/
9494
public async validateEmbedder(embedder: IEmbedder): Promise<{ valid: boolean; error?: string }> {
9595
try {
96-
return await embedder.validateConfiguration()
96+
// Add a timeout to prevent hanging when the embedder service is unavailable
97+
const VALIDATION_TIMEOUT_MS = 5000 // 5 seconds timeout
98+
99+
const timeoutPromise = new Promise<{ valid: boolean; error: string }>((_, reject) => {
100+
setTimeout(() => {
101+
reject(
102+
new Error(
103+
"Failed to connect to the embedder service. Please check your connection settings and ensure the service is running.",
104+
),
105+
)
106+
}, VALIDATION_TIMEOUT_MS)
107+
})
108+
109+
const validationPromise = embedder.validateConfiguration()
110+
111+
// Race between validation and timeout
112+
return await Promise.race([validationPromise, timeoutPromise])
97113
} catch (error) {
98114
// Capture telemetry for the error
99115
TelemetryService.instance.captureEvent(TelemetryEventName.CODE_INDEX_ERROR, {

0 commit comments

Comments
 (0)