@@ -50,7 +50,8 @@ class NetPyNE extends React.Component {
5050 this . loaded = false ;
5151 this . kernelRestartState = {
5252 state : "idle" ,
53- kernelID : undefined
53+ kernelID : undefined ,
54+ crashLoop : false
5455 }
5556 }
5657
@@ -99,32 +100,38 @@ class NetPyNE extends React.Component {
99100 console . log ( "Replaying all commands since the beginning of the session" )
100101 replayAll ( this . kernelRestartState . kernelID )
101102 this . kernelRestartState = {
103+ ...this . kernelRestartState ,
102104 state : "idle" ,
103- kernelID : undefined
105+ kernelID : undefined ,
104106 }
105107 }
106108 case "idle" :
107109 if ( type === "kernel_connected" ) {
108110 console . log ( "Kernel is connecting/starting, being init" )
109111 this . kernelRestartState = {
112+ ...this . kernelRestartState ,
110113 state : "init" ,
111114 kernelID : kernel . id
112115 }
113116 }
114117 else if ( type === "kernel_autorestarting" ) {
115118 console . log ( "Kernel restart event caught, trying to re-init the current model" )
116119 this . kernelRestartState = {
120+ ...this . kernelRestartState ,
117121 state : "restarting" ,
118122 kernelID : kernel . id
119123 }
120- this . props . dispatchAction ( openDialog ( {
121- title : "Kernel restart" ,
122- message : "An action occured that made the kernel restart. We are reloading your model and all the actions you applied on it."
123- } ) )
124+ if ( ! this . kernelRestartState . crashLoop ) {
125+ this . props . dispatchAction ( openDialog ( {
126+ title : "Kernel restart" ,
127+ message : "An action occured that made the kernel restart. We are reloading your model and all the actions you applied on it."
128+ } ) )
129+ }
124130 }
125131 else if ( type === "kernel_restarting" ) {
126132 console . log ( "Kernel restart, perhaps it's a special restart?" )
127133 this . kernelRestartState = {
134+ ...this . kernelRestartState ,
128135 state : "special_restart" ,
129136 kernelID : kernel . id
130137 }
@@ -133,27 +140,58 @@ class NetPyNE extends React.Component {
133140 if ( type === "kernel_ready" ) {
134141 console . log ( "Kernel properly initialized" )
135142 this . kernelRestartState = {
143+ ...this . kernelRestartState ,
136144 state : "idle" ,
137- kernelID : undefined
145+ kernelID : undefined ,
138146 }
139147 }
140148 case "special_restart" :
141149 if ( type == "kernel_autorestarting" ) {
142150 console . log ( "Kernel autorestart after a start, we might not have the ready event, we force it then" )
143151 replayAll ( this . kernelRestartState . kernelID )
144152 this . kernelRestartState = {
153+ ...this . kernelRestartState ,
145154 state : 'restarting' ,
146- kernelID : kernel . id
155+ kernelID : kernel . id ,
147156 }
148157 } else {
158+ console . log ( "Regular restart detected" )
149159 this . kernelRestartState = {
160+ ...this . kernelRestartState ,
150161 state : 'idle' ,
151- kernelID : undefined
162+ kernelID : undefined ,
152163 }
153164 }
154165 }
155166 }
156167 window . addEventListener ( 'kernelstatus' , handleKernelRestart )
168+
169+ // Dedicated code to handle crash loops
170+ const kernelRestartLoopHandler = ( ) => {
171+ if ( ! this . kernelRestartState . crashLoop ) {
172+ this . props . dispatchAction ( openDialog ( {
173+ title : "Kernel restart loop stabilization" ,
174+ message : "One of your actions triggered a kernel restart loop. We are trying to identify the faulty command and to restore your model until this point. Close this window and wait for the kernel stabilization notification."
175+ } ) )
176+ } else {
177+ clearTimeout ( this . kernelRestartState . crashLoop )
178+ }
179+ const taskID = setTimeout ( ( _this ) => {
180+ this . props . dispatchAction ( openDialog ( {
181+ title : "Kernel restart loop stabilized" ,
182+ message : "The kernel is now stabilized."
183+ } ) ) ;
184+ this . kernelRestartState = {
185+ ...this . kernelRestartState ,
186+ crashLoop : false
187+ }
188+ } , 8000 , this )
189+ this . kernelRestartState = {
190+ ...this . kernelRestartState ,
191+ crashLoop : taskID
192+ }
193+ }
194+ window . addEventListener ( 'kernelRestartLoop' , kernelRestartLoopHandler )
157195 }
158196
159197 componentWillUnmount ( ) {
0 commit comments