Skip to content

Commit 068ea0f

Browse files
authored
fix(logger): prevent module from blocking activation (#3119)
## Problem The logging activate function has several fs calls that could potentially cause issues on activation. ## Solution Don't block on non-critical functionality
1 parent 183dd3a commit 068ea0f

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Improve extension start-up performance, especially on devices with slower file systems"
4+
}

src/shared/logger/activation.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ export async function activate(
7474
getLogger().debug(`Logging started: ${logUri}`)
7575

7676
const commands = new Logging(logUri, mainLogger)
77-
extensionContext.subscriptions.push(
78-
...Object.values(Logging.declared).map(c => c.register(commands)),
79-
await createLogWatcher(logUri.fsPath)
80-
)
77+
extensionContext.subscriptions.push(...Object.values(Logging.declared).map(c => c.register(commands)))
78+
79+
createLogWatcher(logUri)
80+
.then(sub => {
81+
extensionContext.subscriptions.push(sub)
82+
})
83+
.catch(err => {
84+
getLogger().warn('Failed to start log file watcher: %s', err)
85+
})
8186

8287
cleanLogFiles(path.dirname(logUri.fsPath)).catch(err => {
83-
getLogger().warn('Failed to clean-up old logs: %s', (err as Error).message)
88+
getLogger().warn('Failed to clean-up old logs: %s', err)
8489
})
8590
}
8691

@@ -152,25 +157,24 @@ function makeLogFilename(): string {
152157
/**
153158
* Watches for renames on the log file and notifies the user.
154159
*/
155-
async function createLogWatcher(logPath: string): Promise<vscode.Disposable> {
156-
const exists = await waitUntil(() => fs.pathExists(logPath), { interval: 1000, timeout: 60000 })
160+
async function createLogWatcher(logFile: vscode.Uri): Promise<vscode.Disposable> {
161+
const exists = await waitUntil(() => SystemUtilities.fileExists(logFile), { interval: 1000, timeout: 60000 })
157162

158163
if (!exists) {
159-
getLogger().warn(`Log file ${logPath} does not exist!`)
164+
getLogger().warn(`Log file ${logFile.path} does not exist!`)
160165
return { dispose: () => {} }
161166
}
162167

163168
let checking = false
164169
// TODO: fs.watch() has many problems, consider instead:
165170
// - https://github.com/paulmillr/chokidar
166171
// - https://www.npmjs.com/package/fb-watchman
167-
const watcher = fs.watch(logPath, async eventType => {
172+
const watcher = fs.watch(logFile.fsPath, async eventType => {
168173
if (checking || eventType !== 'rename') {
169174
return
170175
}
171176
checking = true
172-
const exists = await fs.pathExists(logPath).catch(() => true)
173-
if (!exists) {
177+
if (!(await SystemUtilities.fileExists(logFile))) {
174178
vscode.window.showWarningMessage(
175179
localize('AWS.log.logFileMove', 'The log file for this session has been moved or deleted.')
176180
)

0 commit comments

Comments
 (0)