@@ -114,6 +114,37 @@ const readEnvPath = (env: NodeJS.ProcessEnv): Option.Option<string> =>
114114
115115const normalizeRuntimeDir = ( value : string ) : string => value . replace ( / \/ + $ / u, "" ) ;
116116
117+ const APPIMAGE_SEARCH_PATH_ENV_NAMES = [ "PATH" , "LD_LIBRARY_PATH" , "XDG_DATA_DIRS" ] as const ;
118+
119+ // The AppImage runtime mounts each launch at `$TMPDIR/.mount_<id>` and prepends
120+ // it to the search paths above. A launch started from a shell that inherited an
121+ // earlier launch's env carries that mount too, and once it is unmounted every
122+ // spawn that walks PATH (git first of all) fails with ENOTCONN.
123+ const APPIMAGE_MOUNT_ROOT = / ^ ( .* ?\/ \. m o u n t _ [ ^ / ] + ) (?: \/ | $ ) / u;
124+
125+ const stripStaleAppImageMounts = ( env : NodeJS . ProcessEnv ) : void => {
126+ if ( env . APPIMAGE === undefined && env . APPDIR === undefined ) return ;
127+ const appDir = env . APPDIR === undefined ? undefined : normalizeRuntimeDir ( env . APPDIR ) ;
128+ for ( const name of APPIMAGE_SEARCH_PATH_ENV_NAMES ) {
129+ const value = env [ name ] ;
130+ if ( value === undefined ) continue ;
131+ // glibc's loader also splits LD_LIBRARY_PATH on `;`.
132+ const segments = value . split ( name === "LD_LIBRARY_PATH" ? / [: ; ] / u : ":" ) ;
133+ const kept = segments . filter ( ( segment ) => {
134+ const mountRoot = APPIMAGE_MOUNT_ROOT . exec ( segment ) ?. [ 1 ] ;
135+ return mountRoot === undefined || mountRoot === appDir ;
136+ } ) ;
137+ if ( kept . length === segments . length ) continue ;
138+ if ( kept . length === 0 ) {
139+ delete env [ name ] ;
140+ } else {
141+ // An empty segment is the current dir to the loader and to PATH lookup,
142+ // but a lone one joins to "", which reads as unset.
143+ env [ name ] = kept . join ( ":" ) || ":" ;
144+ }
145+ }
146+ } ;
147+
117148const linuxRuntimeDirCandidates = (
118149 env : NodeJS . ProcessEnv ,
119150 uid : number | undefined ,
@@ -430,6 +461,9 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
430461 if ( Option . isSome ( mergedPath ) ) {
431462 config . env . PATH = mergedPath . value ;
432463 }
464+ // The server, relaunch and updater all inherit process.env, so scrubbing
465+ // here keeps earlier AppImage launches' mounts out of every one of them.
466+ stripStaleAppImageMounts ( config . env ) ;
433467 if ( ! config . env . SSH_AUTH_SOCK && shellEnvironment . SSH_AUTH_SOCK ) {
434468 config . env . SSH_AUTH_SOCK = shellEnvironment . SSH_AUTH_SOCK ;
435469 }
0 commit comments