@@ -99,16 +99,17 @@ function detachCached(s: State, name: string): () => Promise<void> {
9999}
100100
101101let disposerRegistered = false
102- /** Close a project's connectors and tunnels when its instance is disposed (`/instance/dispose`, reload). */
102+ /**
103+ * Close a project's connectors, in-flight connects and tunnels when its instance is disposed (`/instance/dispose`,
104+ * config updates, reload). Its configs stay: they may hold session-only credentials from `warehouse_add` (no OS
105+ * credential store), which must last for the process, and a populated registry is never re-read anyway.
106+ */
103107function ensureDisposer ( ) : void {
104108 if ( disposerRegistered ) return
105109 disposerRegistered = true
106110 registerDisposer ( async ( directory ) => {
107- const key = path . resolve ( directory )
108- const s = states . get ( key )
109- if ( ! s ) return
110- states . delete ( key )
111- await closeState ( s )
111+ const s = states . get ( path . resolve ( directory ) )
112+ if ( s ) await closeState ( s )
112113 } )
113114}
114115
@@ -724,7 +725,11 @@ export async function get(name: string): Promise<Connector> {
724725 } )
725726 } catch { }
726727 return connector
727- } catch ( e ) {
728+ } catch ( caught ) {
729+ // altimate_change start — an attempt dropped by reload/remove/add/dispose fails with whatever its closed tunnel
730+ // or socket raised; report it as superseded (with the retry hint), not as a broken connection
731+ const e = current ( ) ? caught : SUPERSEDED ( name )
732+ // altimate_change end
728733 fileLog ( "WARN" , "warehouse-connect" , "connect failed" , {
729734 name,
730735 type : config ?. type ,
@@ -943,19 +948,19 @@ export async function remove(name: string): Promise<{ success: boolean; error?:
943948 // later reconnect on that account be put down to another connection that shares it.
944949 const inflight = s . pending . has ( name )
945950 const projectConfigPath = localConfigPath ( )
946- // One synchronous step before any await: the in-flight connect is invalidated (and its tunnel closed), the
947- // config is gone from memory and from the global file, so no connect or empty-registry re-read can bring it back,
948- // and the cached connector and tunnel are detached.
949- dropAttempt ( s , name )
950- s . configs . delete ( name )
951- const release = detachCached ( s , name )
951+ // One synchronous step before any await. The global file is written first, so a failed write leaves this
952+ // project's state untouched. Then the in-flight connect is invalidated (and its tunnel closed), the config is
953+ // gone so no connect or empty-registry re-read can bring it back, and the cached connector and tunnel are
954+ // detached. Only a file that holds the entry is rewritten (a missing global directory is not an error).
952955 const globalPath = globalConfigPath ( )
953956 const existing = loadFromFile ( globalPath )
954- // Only a file that holds the entry is rewritten (a missing global directory is not an error).
955957 if ( Object . hasOwn ( existing , name ) ) {
956958 delete existing [ name ]
957959 fs . writeFileSync ( globalPath , JSON . stringify ( existing , null , 2 ) , "utf-8" )
958960 }
961+ dropAttempt ( s , name )
962+ s . configs . delete ( name )
963+ const release = detachCached ( s , name )
959964 await release ( )
960965 if ( ! inflight ) ReconnectLog . forget ( name )
961966 // altimate_change end
0 commit comments