@@ -191,6 +191,43 @@ public function testConnectCancellationWillNotInvokeSocksConnectorWhenProcessBec
191191 Loop ::run ();
192192 }
193193
194+ public function testConnectWillStartNewProcessWhenPreviousProcessExitsAfterPortListenerMessage ()
195+ {
196+ $ connector = new SshSocksConnector ('host ' );
197+
198+ $ ref = new \ReflectionProperty ($ connector , 'cmd ' );
199+ if (PHP_VERSION_ID < 80100 ) {
200+ $ ref ->setAccessible (true );
201+ }
202+ $ ref ->setValue ($ connector , 'echo "debug1: channel 0: new [port listener]" >&2; exec sleep 0.1; # ' );
203+
204+ $ deferred = new Deferred ();
205+ $ socks = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
206+ $ socks ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:80 ' )->willReturn ($ deferred ->promise ());
207+
208+ $ ref = new \ReflectionProperty ($ connector , 'socks ' );
209+ if (PHP_VERSION_ID < 80100 ) {
210+ $ ref ->setAccessible (true );
211+ }
212+ $ ref ->setValue ($ connector , $ socks );
213+
214+ $ connector ->connect ('example.com:80 ' );
215+
216+ $ onRejected = $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('RuntimeException ' ));
217+ Loop ::addTimer (0.5 , function () use ($ connector , $ onRejected ) {
218+ $ ref = new \ReflectionProperty ($ connector , 'cmd ' );
219+ if (PHP_VERSION_ID < 80100 ) {
220+ $ ref ->setAccessible (true );
221+ }
222+ $ ref ->setValue ($ connector , 'echo "Connection closed by remote host" >&2; exit 255; # ' );
223+
224+ $ promise = $ connector ->connect ('example.com:80 ' );
225+ $ promise ->then (null , $ onRejected );
226+ });
227+
228+ Loop ::run ();
229+ }
230+
194231 public function testConnectWillTerminateNewProcessWhenPreviousProcessExitsLateAfterIdleTimeout ()
195232 {
196233 $ connector = new SshSocksConnector ('host ' );
0 commit comments