zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
19.63k stars 616 forks source link

Fails to read creation time for exited sessions on musl libc #3114

Open pedromfedricci opened 5 months ago

pedromfedricci commented 5 months ago

2. Issues with the Zellij UI / behavior / crash

Basic information

binary: https://github.com/zellij-org/zellij/releases/download/v0.39.2/zellij-x86_64-unknown-linux-musl.tar.gz zellij --version: zellij 0.39.2 libc: musl libc v1.1.24 cross: ghcr.io/cross-rs/x86_64-unknown-linux-musl:0.2.5

Issue description

The recent Session Resurrection features (CLI and Session Manager) fail to read the creation time (ctime) for exited session files on musl libc since both Rust's std and the libc crate do not support it. Libc only supports statx for gnu and so std does not provide statx for musl. Because of this, the ReadAllSessionInfosOnMachine background job will always send the value 0 (Duration's default) as the current duration for exited sessions, code location.

Zellij ls zellij-ls-0 39 2-musl

Zellij session-manager zellij-session-manager-0 39 2-musl

Since the ReadAllSessionInfosOnMachine background job fetches session data in a loop, this issue also happens to fill the log file with Failed to read created stamp of resurrection file: Error { kind: Unsupported, message: "creation time is not available on this platform currently" quite fast, writing a new entry for every tick (default 1sec) x no. of active sessions x no. of exited sessions with a session-layout.kdl file.

Minimal reproduction

  1. Download Zellij for linux/musl: https://github.com/zellij-org/zellij/releases/download/v0.39.2/zellij-x86_64-unknown-linux-musl.tar.gz
  2. Run one or more sessions with the downloaded Zellij: <your_path>/zellij
  3. Wait for about 1 minute so that Zellij will write layout snapshots for your new sessions
  4. Confirm that session-layout.kdl files have been written with: ls ~/.cache/zellij/0.39.2/session_info/*
  5. Close all sessions from step 2
  6. Check their exit status and wrong duration with <your_path>/zellij ls (created: 0s ago is incorrect)
  7. Run a new session like step 2
  8. Check incoming errors in the log file with: tail -f /tmp/zellij-1000/zellij-log/zellij.log

Other relevant information

Building Zellij in a linux/gnu environment (cargo build --release or cargo install zellij) does not have such issues.

pedromfedricci commented 5 months ago

Some possible solutions that I could think of (other designs and ideas are welcome):

  1. Keep current behavior for musl targets (always shows 0s ago) and either suppress the error entirely or cache it and then log it only once.
  2. When targeting musl specifically, show the duration since last modification (that would be the last time Zellij took a snapshot) for exited sessions. This of course will not represent the "created at" duration accurately.
  3. Update the behavior for all targets to show "last snapshot" instead of creation. The UI would read something like "Last Save", "Saved", etc. This would deviate the most from the current experience though. But one could argue that "last saved time" is a better hint to what the session will look like in comparison to its full duration.
steakhutzeee commented 2 months ago

I'm experiencing this too.

Also a question, so we need to wait 1 minute for the session to be cached?

If I create a session, issue some random command and then quit with Ctrl + q then I can't see the session with zellij ls

pedromfedricci commented 2 months ago

Yeah you need to wait for at least the serialization_interval's value (default 60 seconds) and session_serialization must be set to true (which is the default value).

steakhutzeee commented 2 months ago

Yeah you need to wait for at least the serialization_interval's value (default 60 seconds) and session_serialization must be set to true (which is the default value).

Thanks! Can this time be configured? Do not see it in the docs.

pedromfedricci commented 2 months ago

It is not in the docs page yet, but you can add to your config.kdl like this (value is in seconds):

serialization_interval 300