-
-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[add] detect and recover from kernel auto restarts #5558
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ import { | |
childOf, | ||
createMessage, | ||
JupyterMessage, | ||
ofMessageType | ||
ofMessageType, | ||
kernelStatuses, | ||
kernelInfoRequest | ||
} from "@nteract/messaging"; | ||
import { sendNotification } from "@nteract/mythic-notifications"; | ||
import { AnyAction } from "redux"; | ||
|
@@ -17,9 +19,11 @@ import { | |
first, | ||
map, | ||
mergeMap, | ||
pairwise, | ||
switchMap, | ||
take, | ||
takeUntil, | ||
tap, | ||
timeout | ||
} from "rxjs/operators"; | ||
|
||
|
@@ -79,6 +83,73 @@ export const watchExecutionStateEpic = ( | |
) | ||
); | ||
|
||
/** | ||
* Jupyter has options to automatically restart the kernel on crash for a max-retry of 5 retries. | ||
* Monitor for the kernel to have successfully restarted (sent as a "restarting" status followed by a "starting"). | ||
* If all 5 retries fail, the kernel status is reported as "dead". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
* | ||
* @oaram {ActionObservable} action$ ActionObservable for LAUNCH_KERNEL_SUCCESSFUL action | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
export const watchForKernelAutoRestartEpic = ( | ||
action$: Observable< | ||
actions.NewKernelAction | actions.KillKernelSuccessful | ||
>, | ||
state$: StateObservable<AppState> | ||
) => | ||
action$.pipe( | ||
ofType(actions.LAUNCH_KERNEL_SUCCESSFUL), | ||
// Only accept jupyter servers for the host with this epic | ||
filter(() => selectors.isCurrentHostJupyter(state$.value)), | ||
switchMap( | ||
(action: actions.NewKernelAction | actions.KillKernelSuccessful) => { | ||
const { kernel, kernelRef, contentRef } = (action as actions.NewKernelAction).payload; | ||
|
||
return kernel.channels.pipe( | ||
kernelStatuses(), | ||
pairwise(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow this one is new to me, very cool. |
||
filter( | ||
([previousStatus, currentStatus]: [KernelStatus, KernelStatus]) => | ||
previousStatus === KernelStatus.Restarting && currentStatus === KernelStatus.Starting | ||
), | ||
tap(() => { | ||
// to avoid getting stuck in the "starting" state, nudge kernel with kernel_info_request to bring the status to Idle. | ||
// TODO: test can't seem to identify next on subject. For now, check before calling | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since channels is a plain observable in some of the tests rather than a subject, it doesn't have |
||
if (kernel.channels.next) { | ||
kernel.channels.next(kernelInfoRequest()); | ||
} | ||
}), | ||
map(() => | ||
actions.kernelAutoRestarted({ | ||
kernelRef | ||
}) | ||
), | ||
takeUntil( | ||
action$.pipe( | ||
ofType(actions.KILL_KERNEL_SUCCESSFUL), | ||
filter( | ||
( | ||
killAction: | ||
| actions.KillKernelSuccessful | ||
| actions.NewKernelAction | ||
) => killAction.payload.kernelRef === action.payload.kernelRef | ||
) | ||
) | ||
), | ||
catchError((error: Error) => { | ||
return of( | ||
actions.executeFailed({ | ||
error: new Error( | ||
"The WebSocket connection has unexpectedly disconnected." | ||
), | ||
code: errors.EXEC_WEBSOCKET_ERROR, | ||
contentRef | ||
}) | ||
); | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
/** | ||
* Send a kernel_info_request to the kernel. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, this works nicely for tests. 😎