Errors: Ignore errors from async when quitting #1918
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a bug where, upon successfully quitting zellij, the log would contain error messages from the
async
tasks associated with the PTYs about failing to send a message to the Screen.The Situation
The errors look like this in the logs:
This is undesirable for a number of reasons:
TerminalBytes::listen
functions loop, and there is one per zellij pane. However, we do not get an error per zellij pane in the logs.It turns out that 3 was actually a mistake in the implementation of the
ToAnyhow
trait for theSendError
type. With 3 fixed the errors now look like this:This also fixes 4, because now we get an error report like this for every pane that was open when we terminated zellij (e.g. with
Ctrl+q
). Also, the error "report" now matches the expectations of how it should look given the code, and it tells us what really went wrong.The Cause
As the error message now correctly suggests, this error originates from failing to send a message to the
Screen
thread to render the screen. At the end of theTerminalBytes::listen
function, after we have broken out of the main control loop, we send a final render instruction to the screen.However, when quitting zellij, the individual threads currently don't adhere to a strict order when exiting and do not wait on each other. Therefore, the
screen
thread responsible for handling render requests may have exited before the individual pane tasks manage to send their final render requests. While this is technically an error, it is expected in the current state of the application.Solving the problem
The problem is now solved by sending the final render instruction but ignoring the result. This may have side-effects for regular application operation, e.g. when exiting a single pane and the screen isn't re-rendered. However, this is likely solved by the next render instruction, which will likely happen shortly afterwards.
A long-term solution may include zellij entering a global "quitting" state, which can be checked for from any part of the code to handle specific (types of) errors gracefully. Alternatively, it may be possible to have the threads wait on each other when terminating the application so all IPC messages get to their destinations before closing IPC channels. However, this is out of scope for this PR.