You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
When writing to our SSO cache we noticed malformed json files that had
our token. As a solution we did an "atomic" write where we wrote a temp
file then renamed. This prevented the content from being malformed due to
a separate write.
The issue is that the combination of writing a temp file, then renaming it
fails sometimes as indicated by our metric `aws_refreshCredentials` where we
were seeing a 'FileNotFound' error.
Solution:
Move the atomic write logic in to `FileSystem.writeFile()` itself, where it is
triggered as part of an argument to the function.
Additionally when the `rename()` method is called under the hood of `writeFile()`,
we validate that the file exists by retrying a few times. We suspect this to be
the culprit of the `FileNotFound` error, see the comments in code for more info.
Signed-off-by: Nikolas Komonen <[email protected]>
* We were seeing 'FileNotFound' errors during renames, even though we did a `writeFile()` right before the rename.
259
+
* The error looks to be from here: https://github.com/microsoft/vscode/blob/09d5f4efc5089ce2fc5c8f6aeb51d728d7f4e758/src/vs/platform/files/node/diskFileSystemProvider.ts#L747
260
+
* So a guess is that the exists()(stat() under the hood) call needs to be retried since there may be a race condition.
261
+
*/
262
+
letattempts=0
263
+
constisExists=awaitwaitUntil(async()=>{
264
+
constresult=awaitfs.exists(oldUri)
265
+
attempts+=1
266
+
returnresult
267
+
},FileSystem.renameTimeoutOpts)
268
+
// TODO: Move the `ide_fileSystem` or some variation of this metric in to common telemetry
269
+
// TODO: Deduplicate the `ide_fileSystem` call. Maybe have a method that all operations pass through which wraps the call in telemetry.
270
+
// Then look to report telemetry failure events.
271
+
constscrubbedPath=scrubNames(oldUri.fsPath)
272
+
if(!isExists){
273
+
// source path never existed after multiple attempts.
274
+
// Either the file never existed, or had we waited longer it would have. We won't know.
275
+
telemetry.ide_fileSystem.emit({
276
+
result: 'Failed',
277
+
action: 'rename',
278
+
reason: 'SourceNotExists',
279
+
reasonDesc: `After ${FileSystem.renameTimeoutOpts.timeout}ms the source path did not exist: ${scrubbedPath}`,
280
+
})
281
+
}elseif(attempts>1){
282
+
// Indicates that rename() would have failed if we had not waited for it to exist.
283
+
telemetry.ide_fileSystem.emit({
284
+
result: 'Succeeded',
285
+
action: 'rename',
286
+
reason: 'RenameRaceCondition',
287
+
reasonDesc: `After multiple attempts the source path existed: ${scrubbedPath}`,
0 commit comments