Skip to content

Commit d55debd

Browse files
more atomic HB file deletion
Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 673ddf1 commit d55debd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/core/src/shared/crashMonitoring.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,13 @@ export class FileSystemState {
517517

518518
private async deleteHeartbeatFile(ext: ExtInstanceId | ExtInstance, ctx: string) {
519519
// IMPORTANT: Must use NodeFs here since this is used during shutdown
520-
const func = () => nodeFs.rm(this.makeStateFilePath(ext), { force: true })
520+
const func = async () => {
521+
const filePath = this.makeStateFilePath(ext)
522+
// Even when deleting a file, if there is an open file handle it may still exist. This empties the
523+
// contents, so that any following reads will get no data.
524+
await nodeFs.writeFile(filePath, '')
525+
await nodeFs.rm(filePath, { force: true })
526+
}
521527
const funcWithCtx = () => withFailCtx(ctx, func)
522528
const funcWithRetries = withRetries(funcWithCtx, { maxRetries: 6, delay: 100, backoff: 2 })
523529
await funcWithRetries

0 commit comments

Comments
 (0)