File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -673,6 +673,10 @@ export class FluentSocket extends EventEmitter {
673673 */
674674 public disconnect ( ) : Promise < void > {
675675 return new Promise ( resolve => {
676+ if ( this . reconnectTimeoutId !== null ) {
677+ clearTimeout ( this . reconnectTimeoutId ) ;
678+ this . reconnectTimeoutId = null ;
679+ }
676680 if ( this . socket !== null ) {
677681 this . state = SocketState . DISCONNECTING ;
678682 this . socket . end ( resolve ) ;
Original file line number Diff line number Diff line change @@ -262,6 +262,34 @@ describe("FluentSocket", () => {
262262 } ) ;
263263 } ) ;
264264
265+ it ( "should not reconnect after disconnect if the remote socket is unavilable" , done => {
266+ const { socket, stream, connectStub} = createFluentSocket ( { reconnect : { } } ) ;
267+
268+ expect ( ( < any > socket ) . reconnectEnabled ) . to . be . true ;
269+
270+ socket . connect ( ) ;
271+
272+ sinon . assert . calledOnce ( connectStub ) ;
273+
274+ const spy = sinon . spy ( socket , "connect" ) ;
275+
276+ socket . once ( FluentSocketEvent . WRITABLE , async ( ) => {
277+ socket . once ( FluentSocketEvent . CLOSE , async ( ) => {
278+ setImmediate ( async ( ) => {
279+ expect ( ( < any > socket ) . reconnectTimeoutId ) . not . to . be . null ;
280+ await expect ( socket . disconnect ( ) ) . to . eventually . be . equal ( undefined ) ;
281+ expect ( ( < any > socket ) . reconnectTimeoutId ) . to . be . null ;
282+ sinon . assert . notCalled ( spy ) ;
283+ done ( ) ;
284+ } ) ;
285+ } ) ;
286+
287+ setImmediate ( ( ) => {
288+ stream . socket . emit ( "close" ) ;
289+ } ) ;
290+ } ) ;
291+ } ) ;
292+
265293 it ( "should reject writes if socket is not writable" , done => {
266294 const { socket, stream, connectStub} = createFluentSocket ( ) ;
267295
You can’t perform that action at this time.
0 commit comments