-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve diagnostics for kernel supervisor startup failures (#5705)
This change improves diagnostics and logging for (hopefully rare) cases in which the kernel supervisor _itself_ cannot start. This is distinct from the cases where R or Python can't start. So far we've seen just one of these in the wild, as a result of running on an unsupported OS. The approach is to borrow the wrapper script technique from the Jupyter Adapter (formerly used to invoke the kernels themselves). The wrapper script acts as a sort of supervisor for the supervisor; it eats the output of the supervisor process and writes it to a file. If the supervisor exits unexpectedly at startup, the output file is written to the log channel, and the user is directed there to view errors. As an additional benefit, this runs the supervisor under a `bash` process on Unix-alikes, so any environment variables or configuration set up in `.bashrc` (etc) will now be available to the supervisor. Addresses #5611 . May help us figure out #5337. ### QA Notes An easy way to test this is to replace your `kcserver` binary with a shell script that emits some nonsense and then exits immediately with a nonzero status code. If you're feeling ambitious, you could also test this on the OS named in #5611. Also, did you know that the [longest worm in the world](https://en.wikipedia.org/wiki/Lineus_longissimus) can reach up to 55 meters? Crazy.
- Loading branch information
Showing
4 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"binaries": [ | ||
{ | ||
"from": "resources/supervisor-wrapper.*", | ||
"to": "resources" | ||
} | ||
] | ||
} |
44 changes: 44 additions & 0 deletions
44
extensions/positron-supervisor/resources/supervisor-wrapper.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@echo off | ||
|
||
REM --------------------------------------------------------------------------------------------- | ||
REM Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
REM --------------------------------------------------------------------------------------------- | ||
|
||
REM This script is used to run a program and capture its output to a file. It is | ||
REM used to capture the output of the supervisor process so that it can be displayed | ||
REM in the UI in the case of a startup failure. | ||
|
||
REM Check that the user provided at least two arguments; the first is the output | ||
REM file and the second is the program to run and any arguments. If not, print a | ||
REM usage message and exit with an error code. | ||
|
||
if "%~2"=="" ( | ||
echo Usage: %0 ^<output-file^> ^<program^> [program-args...] >&2 | ||
exit /b 1 | ||
) | ||
|
||
REM The first argument is the output file; consume it. | ||
set output_file=%1 | ||
shift | ||
|
||
REM `shift` doesn't affect `%*`, so we have to manually remove the first argument | ||
set "args=" | ||
:parse | ||
if "%~1" neq "" ( | ||
set args=%args% %1 | ||
shift | ||
goto :parse | ||
) | ||
if defined args set args=%args:~1% | ||
|
||
REM Print the command line to the log file | ||
echo %args% >> "%output_file%" | ||
|
||
REM Run the program with its arguments and capture the output | ||
%args% >> "%output_file%" | ||
|
||
REM Save the exit code of the program | ||
set exit_code=%ERRORLEVEL% | ||
|
||
REM Exit with the same code as the program so that the caller can correctly report errors | ||
exit /b exit_code |
34 changes: 34 additions & 0 deletions
34
extensions/positron-supervisor/resources/supervisor-wrapper.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
# --------------------------------------------------------------------------------------------- | ||
# Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
# Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
# --------------------------------------------------------------------------------------------- | ||
|
||
# This script is used to run a program and capture its output to a file. It is | ||
# used to capture the output of the supervisor process so that it can be displayed | ||
# in the UI in the case of a startup failure | ||
|
||
# Check that the user provided at least two arguments; the first is the output | ||
# file and the second is the program to run and any arguments. If not, print a | ||
# usage message and exit with an error code. | ||
if [ $# -lt 2 ]; then | ||
echo "Usage: $0 <output-file> <program> [program-args...]" >&2 | ||
exit 1 | ||
fi | ||
|
||
# The first argument is the output file; consume it. | ||
output_file="$1" | ||
shift | ||
|
||
# Print the command line to the log file | ||
echo "$@" >> "$output_file" | ||
|
||
# Run the program with its arguments, redirecting stdout and stderr to the output file | ||
"$@" >> "$output_file" 2>&1 | ||
|
||
# Save the exit code of the program | ||
exit_code=$? | ||
|
||
# Exit with the same code as the program so that the caller can correctly report errors | ||
exit $exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters