@@ -78,6 +78,7 @@ export class GatewayClientTransport implements ConnectableOpenClawTransport {
7878 private readonly options : GatewayClientTransportOptions ;
7979 private client : GatewayClientLike | null = null ;
8080 private connectPromise : Promise < void > | null = null ;
81+ private rejectPendingConnect : ( ( error : Error ) => void ) | null = null ;
8182 private closePromise : Promise < void > | null = null ;
8283
8384 constructor ( options : GatewayClientTransportOptions = { } ) {
@@ -89,6 +90,7 @@ export class GatewayClientTransport implements ConnectableOpenClawTransport {
8990 return this . connectPromise ;
9091 }
9192 this . connectPromise = new Promise < void > ( ( resolve , reject ) => {
93+ this . rejectPendingConnect = reject ;
9294 const client = new GatewayClient ( {
9395 ...this . options ,
9496 onEvent : ( event : unknown ) => {
@@ -98,6 +100,7 @@ export class GatewayClientTransport implements ConnectableOpenClawTransport {
98100 } ,
99101 onHelloOk : ( _hello : unknown ) => {
100102 this . options . onHelloOk ?.( _hello ) ;
103+ this . rejectPendingConnect = null ;
101104 resolve ( ) ;
102105 } ,
103106 onConnectError : ( error : Error ) => {
@@ -109,6 +112,7 @@ export class GatewayClientTransport implements ConnectableOpenClawTransport {
109112 this . connectPromise = null ;
110113 }
111114 void client . stopAndWait ( ) . catch ( ( ) => { } ) ;
115+ this . rejectPendingConnect = null ;
112116 reject ( error ) ;
113117 } ,
114118 onReconnectPaused : this . options . onReconnectPaused ,
@@ -145,6 +149,9 @@ export class GatewayClientTransport implements ConnectableOpenClawTransport {
145149 this . eventsHub . close ( ) ;
146150 const client = this . client ;
147151 this . client = null ;
152+ const rejectPendingConnect = this . rejectPendingConnect ;
153+ this . rejectPendingConnect = null ;
154+ rejectPendingConnect ?.( new Error ( "gateway transport closed before connect completed" ) ) ;
148155 this . connectPromise = null ;
149156 this . closePromise = client ?. stopAndWait ( ) ?? Promise . resolve ( ) ;
150157 await this . closePromise ;
0 commit comments