Skip to content

fix: avoid double-init of late final _root in NodeDriveService (1.27.4)#73

Merged
gmpassos merged 1 commit into
masterfrom
fix/drive-root-late-double-init
Jun 21, 2026
Merged

fix: avoid double-init of late final _root in NodeDriveService (1.27.4)#73
gmpassos merged 1 commit into
masterfrom
fix/drive-root-late-double-init

Conversation

@gmpassos

Copy link
Copy Markdown
Contributor

Problem

Starting a Windows node and opening a drive session crashed with:

LateInitializationError: Field '_root@...' has already been initialized.
#1  NodeDriveService._root= (node_drive_service.dart)
#2  NodeDriveService.run (node_drive_service.dart:78:7)

This is a regression from #72 / commit bcb029b ("translate MSYS drive-mount root on Windows nodes", v1.27.3). _root is declared late final String (one assignment only), but the new MSYS-translation code assigned it twice on Windows when the path starts with /:

_root = expandUserHome(request.command ?? '.');   // first assignment
if (Platform.isWindows && _root.startsWith('/')) {
  _root = windowsPathFromMsys(_root);              // second assignment -> crash
}

The crash fires on exactly the Windows + MSYS-root case the 1.27.3 fix was meant to support: the session opens, then the drive service dies, taking the node down.

Fix

Resolve the root into a single value via a pure, platform-parameterized static helper NodeDriveService.resolveRoot(command, isWindows: ...), assigned to _root exactly once. Extracting the helper also makes the Windows-only branch unit-testable off Windows.

Tests

  • New test/unit/node/node_drive_service_test.dart covering MSYS translation on Windows, POSIX pass-through (regression guard), already-Windows / non-drive paths, null default, and idempotency.
  • All new tests + version_test pass; dart format + dart analyze clean.

Version

Bumped 1.27.3 -> 1.27.4 (pubspec.yaml, lib/src/version.dart) + CHANGELOG entry.

🤖 Generated with Claude Code

The 1.27.3 MSYS mount-root translation assigned the `late final _root`
field twice on Windows — once on resolve, again on translation — throwing
`LateInitializationError` and crashing NodeDriveService right after the
session began serving, on the exact Windows/MSYS path the 1.27.3 fix
targeted.

Root resolution now computes a single value via the pure, platform-
parameterized `NodeDriveService.resolveRoot`, assigned to `_root` exactly
once. Extracting the static helper also makes the Windows branch unit-
testable off Windows; added test/unit/node/node_drive_service_test.dart.
POSIX nodes were unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gmpassos gmpassos merged commit b075721 into master Jun 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant