Skip to content

Commit 15ba22b

Browse files
authored
Write SDK summary to a temp file and rename (#3740)
Avoid writing partial output to the file that could be concurrently read by another isolate in the same process. Create a temp directory to incrementally write the file, then use `rename` to atomically move it to the location where other isolates may try to read it. It's best to still avoid using the SDK summary from and analysis driver in multiple isolates, but this should reduce flakiness in some cases where they do run concurrently.
1 parent d2a803e commit 15ba22b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

build_resolvers/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
- Require the latest analyzer, and stop passing the `withNullability`
44
parameter which was previously required and is now deprecated.
55
- Bump the min sdk to 3.5.0.
6+
- Fix SDK summary reads when multiple isolates are using build resolvers (not
7+
recommended).
68

79
## 2.4.2
810

build_resolvers/lib/src/sdk_summary.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,23 @@ Future<String> defaultSdkSummaryGenerator() async {
6161
if (needsRebuild) {
6262
var watch = Stopwatch()..start();
6363
_logger.info('Generating SDK summary...');
64-
await summaryFile.create(recursive: true);
64+
await Directory(cacheDir).create(recursive: true);
65+
final tempDir = await Directory(cacheDir).createTemp();
66+
final tempFile = File(p.join(tempDir.path, p.basename(summaryPath)));
67+
await tempFile.create();
6568
final embedderYamlPath =
6669
isFlutter ? p.join(_dartUiPath, '_embedder.yaml') : null;
67-
await summaryFile.writeAsBytes(
70+
await tempFile.writeAsBytes(
6871
await buildSdkSummary(
6972
sdkPath: _runningDartSdkPath,
7073
resourceProvider: PhysicalResourceProvider.INSTANCE,
7174
embedderYamlPath: embedderYamlPath,
7275
),
7376
);
7477

78+
await tempFile.rename(summaryPath);
7579
await _createDepsFile(depsFile, currentDeps);
80+
await tempDir.delete();
7681
watch.stop();
7782
_logger.info('Generating SDK summary completed, took '
7883
'${humanReadable(watch.elapsed)}\n');

0 commit comments

Comments
 (0)