@@ -690,7 +690,7 @@ ProcessProxy.prototype._initAutoInvalidation = function() {
690
690
var self = this ;
691
691
692
692
// the below will run on an interval
693
- setInterval ( function ( ) {
693
+ this . _autoInvalidationInterval = setInterval ( function ( ) {
694
694
695
695
// #1 build list of commands
696
696
var commandsToExec = [ ] ;
@@ -796,14 +796,14 @@ ProcessProxy.prototype.executeCommand = function(command) {
796
796
797
797
self . executeCommands ( [ command ] )
798
798
799
- . then ( function ( cmdResults ) {
799
+ . then ( function ( cmdResults ) {
800
800
801
- fulfill ( cmdResults [ 0 ] ) ;
801
+ fulfill ( cmdResults [ 0 ] ) ;
802
802
803
803
804
- } ) . catch ( function ( error ) {
805
- reject ( error ) ;
806
- } ) ;
804
+ } ) . catch ( function ( error ) {
805
+ reject ( error ) ;
806
+ } ) ;
807
807
808
808
} ) ;
809
809
@@ -907,7 +907,7 @@ ProcessProxy.prototype.executeCommands = function(commands) {
907
907
// write the command, followed by this echo
908
908
// marker so we know that the command is done
909
909
self . _process . stdin . write ( command + '\n' +
910
- 'echo ' + MARKER_DONE + '\n' ) ;
910
+ 'echo ' + MARKER_DONE + '\n' ) ;
911
911
912
912
913
913
}
@@ -920,6 +920,28 @@ ProcessProxy.prototype.executeCommands = function(commands) {
920
920
921
921
} ;
922
922
923
+ /**
924
+ * Called by shutdown to do the actual destruction of
925
+ * this object
926
+ *
927
+ */
928
+ ProcessProxy . prototype . _destroySelf = function ( ) {
929
+ try {
930
+ if ( this . _autoInvalidationConfig ) {
931
+ clearInterval ( this . _autoInvalidationInterval ) ;
932
+ }
933
+ } catch ( error ) {
934
+ this . _log ( 'error' , 'shutdown - error cleaning _autoInvalidationInterval..' + error ) ;
935
+ }
936
+
937
+ try { this . _process . stdin . end ( ) ; } catch ( error ) {
938
+ this . _log ( 'error' , 'shutdown - error _process.stdin.end()..' + error ) ;
939
+ }
940
+ try { this . _process . kill ( ) ; } catch ( error ) {
941
+ this . _log ( 'error' , 'shutdown - error _process.kill()..' + error ) ;
942
+ }
943
+ }
944
+
923
945
/**
924
946
* shutdown() - shuts down the ProcessProxy w/ optional shutdown commands
925
947
* and returns a Promise, when fulfilled contains the results
@@ -945,34 +967,30 @@ ProcessProxy.prototype.shutdown = function(shutdownCommands) {
945
967
946
968
self . _executeCommands ( shutdownCommands , false ) // skip black/whitelists
947
969
948
- . then ( function ( cmdResults ) {
970
+ . then ( function ( cmdResults ) {
949
971
950
- self . _process . stdin . end ( ) ;
951
- self . _process . kill ( ) ;
972
+ self . _destroySelf ( ) ;
973
+ fulfill ( cmdResults ) ; // invoke when done!
952
974
953
- fulfill ( cmdResults ) ; // invoke when done!
975
+ } ) . catch ( function ( exception ) {
976
+ self . _log ( 'error' , "shutdown - shutdownCommands, " +
977
+ " exception thrown: " + exception ) ;
954
978
955
- } ) . catch ( function ( exception ) {
956
- self . _log ( 'error' , "shutdown - shutdownCommands, " +
957
- " exception thrown: " + exception ) ;
958
- self . _process . stdin . end ( ) ;
959
- self . _process . kill ( ) ;
960
- reject ( exception ) ;
961
- } ) ;
979
+ self . _destroySelf ( ) ;
980
+ reject ( exception ) ;
981
+ } ) ;
962
982
963
983
964
- // we are done, no init commands to run...
984
+ // we are done, no shutdown commands to run...
965
985
} else {
966
- self . _process . stdin . end ( ) ;
967
- self . _process . kill ( ) ;
986
+ self . _destroySelf ( ) ;
968
987
fulfill ( null ) ;
969
988
}
970
989
971
990
972
991
} catch ( exception ) {
973
992
self . _log ( 'error' , "shutdown, exception thrown: " + exception ) ;
974
- self . _process . stdin . end ( ) ;
975
- self . _process . kill ( ) ;
993
+ self . _destroySelf ( ) ;
976
994
reject ( exception ) ;
977
995
}
978
996
} ) ;
0 commit comments