File tree Expand file tree Collapse file tree
application/shared-kernel/SharedKernel/Configuration Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,7 +78,13 @@ public static PortAllocation LoadFrom(string repositoryRoot)
7878 var workspaceDirectory = Path . Combine ( repositoryRoot , WorkspaceDirectoryName ) ;
7979 var portFilePath = Path . Combine ( workspaceDirectory , PortFileName ) ;
8080
81- if ( ! File . Exists ( portFilePath ) )
81+ // Treat "file doesn't exist" and "file exists but is empty" as the same condition: both
82+ // mean we need to (re-)bootstrap. The empty case happens when a concurrent caller has
83+ // opened the file with O_CREAT|O_TRUNC but hasn't written yet — overwriting it with the
84+ // same deterministic value is a harmless no-op.
85+ var content = File . Exists ( portFilePath ) ? File . ReadAllText ( portFilePath ) . Trim ( ) : "" ;
86+
87+ if ( content . Length == 0 )
8288 {
8389 var bootstrapPort = IsWorktree ( repositoryRoot )
8490 ? FindFreeBasePortForWorktree ( )
@@ -88,7 +94,6 @@ public static PortAllocation LoadFrom(string repositoryRoot)
8894 return new PortAllocation ( bootstrapPort ) ;
8995 }
9096
91- var content = File . ReadAllText ( portFilePath ) . Trim ( ) ;
9297 if ( ! int . TryParse ( content , out var basePort ) || basePort <= 0 )
9398 {
9499 throw new InvalidOperationException (
You can’t perform that action at this time.
0 commit comments