Skip to content
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

Url object is destroyed after some period of time #2159

Closed
3 tasks done
hankertrix opened this issue Jan 4, 2025 · 2 comments
Closed
3 tasks done

Url object is destroyed after some period of time #2159

hankertrix opened this issue Jan 4, 2025 · 2 comments
Labels
invalid This doesn't seem right

Comments

@hankertrix
Copy link
Contributor

What system are you running Yazi on?

Linux X11

What terminal are you running Yazi in?

Ghostty 1.0.1-dev+0000000

yazi --debug output

Yazi
    Version: 0.4.3 (Arch Linux 2025-01-01)
    Debug  : false
    Triple : x86_64-unknown-linux-gnu (linux-x86_64)
    Rustc  : 1.83.0 (90b35a62 2024-11-26)

Ya
    Version: 0.4.3 (Arch Linux 2025-01-01)

Emulator
    Brand.from_env      : Some(Ghostty)
    Emulator.detect     : Emulator { kind: Left(Ghostty), light: false, cell_size: Some((15, 30)) }
    Emulator.detect_full: Ok(Emulator { kind: Left(Ghostty), light: false, cell_size: Some((15, 30)) })

Adapter
    Adapter.matches: Kgp

Desktop
    XDG_SESSION_TYPE           : Some("x11")
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

NVIM
    NVIM          : false
    Neovim version: 0.10.3

Variables
    SHELL           : Some("/bin/bash")
    EDITOR          : Some("nvim")
    VISUAL          : Some("nvim")
    YAZI_FILE_ONE   : None
    YAZI_CONFIG_HOME: None
    YAZI_ZOXIDE_OPTS: None
    FZF_DEFAULT_OPTS: None

Text Opener
    default     : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-create: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-rename: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : 0
    tmux version       : No such file or directory (os error 2)
    tmux build flags   : enable-sixel=Unknown
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file          : 5.46
    ueberzugpp    : No such file or directory (os error 2)
    ffmpeg/ffprobe: 7.1 / 7.1
    pdftoppm      : 24.12.0
    magick        : 7.1.1-43
    fzf           : 0.57.0
    fd/fdfind     : 10.2.0 / No such file or directory (os error 2)
    rg            : 14.1.1
    chafa         : No such file or directory (os error 2)
    zoxide        : No such file or directory (os error 2)
    7z/7zz        : 24.09 / No such file or directory (os error 2)
    jq            : 1.7.1

Clipboard
    wl-copy/paste: No such file or directory (os error 2) / No such file or directory (os error 2)
    xclip        : 0.13
    xsel         : No such file or directory (os error 2)

Describe the bug

The Url object has a lifetime of some sort and gets destroyed after a while. I'm not sure if this is intended or not, but if it is it should be documented.

Relevant bug report:
hankertrix/augment-command.yazi#8

Minimal reproducer

There's probably no simple reproduction for this bug.

  1. Install hankertrix/augment-command.yazi@0b4352d
  2. Use the keymap.toml below:
[[manager.prepend_keymap]]
on   = [ "l" ]
run  = "plugin augment-command --args='enter'"
desc = "Enter the child directory, or open the file"
  1. Open Yazi and extract an archive.
  2. Observe that the error in extract command: bad argument #1: userdata has been destructed if using enter --no-skip hankertrix/augment-command.yazi#8 occurs.

Anything else?

Interestingly enough, simply creating a new Url to pass to the skip_single_child_directories fixes the issue, i.e. replacing extracted_items_url with Url(extracted_items_path) here makes everything work fine.

Using a string instead also works just fine, as strings don't seem to have a lifetime.

Checklist

  • I tried the latest nightly build, and the issue is still reproducible
  • I updated the debug information (yazi --debug) input box to the nightly that I tried
  • I can reproduce it after disabling all custom configs/plugins (mv ~/.config/yazi ~/.config/yazi-backup)
@sxyazi
Copy link
Owner

sxyazi commented Jan 5, 2025

This is expected behavior.

Yazi's plugin system inherits Rust's ownership and lifetime concepts. All userdata (including Url) are native Rust types that have their own ownership to ensure safe and efficient transfers across different threads, avoiding any memory reallocation overhead.

In this case, the second parameter of manager_emit triggers an ownership transfer. So when a Url is passed as an argument to manager_emit, it is transferred to another thread with zero cost compared to Lua strings.

Currently, documentation about ownership transfer is still missing, but I'll start working on it in the next few days.

Tracked by yazi-rs/yazi-rs.github.io#194, closing in favor of that.

@sxyazi sxyazi closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2025
@sxyazi sxyazi added invalid This doesn't seem right and removed bug Something isn't working labels Jan 5, 2025
@hankertrix
Copy link
Contributor Author

Ahhh I see, that makes sense.

With the support of Url objects for inter-thread communication (previously only Lua primitives were supported), documentation about when the Url object is moved is crucial for plugin developers.

Do you have a quick list of the functions that transfer ownership of the Url object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants