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

plenary.async.uv: Attempt to yield across C-call boundary #252

Open
chuwy opened this issue Oct 5, 2021 · 3 comments
Open

plenary.async.uv: Attempt to yield across C-call boundary #252

chuwy opened this issue Oct 5, 2021 · 3 comments

Comments

@chuwy
Copy link

chuwy commented Oct 5, 2021

I'm starting to write a very minimalistic plugin with async example from README. Basically there's only init.lua file with:

local a = require("plenary.async")

read = function(path)
  local err, fd = a.uv.fs_open(path, "r", 438)
  assert(not err, err)
end

return { read_token = read }

But it fails with the following error, whenever I try to call the function:

E5108: Error executing lua ...te/pack/packer/start/myplugin.nvim/lua/myplugin/init.lua:4: attempt to yield across C-call boundary

Although in fact I see the same error even when call it directly:

:lua require("plenary.async").uv.fs_open("/etc/fstab", "r", 438)

:version output:

:version
NVIM v0.6.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by antonparkhomenko

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/nix/store/nzy87w4j77l1jiyrmxlifn9nv6i1jyc1-neovim-unwrapped-master/share/nvim"
@chuwy
Copy link
Author

chuwy commented Oct 6, 2021

Same error with:

> nvim --clean \
  --cmd set\ rtp+=/Users/antonparkhomenko/.local/share/nvim/site/pack/packer/start/plenary.nvim \
  --cmd ":lua require('plenary.async').uv.fs_open('/Users/antonparkhomenko/.zshrc', 'r', 438)"

And even if I run it with 0.4.4 I get:

E5105: Error while calling lua chunk: [string "<VimL compiled string>"]:1: attempt to yield across C-call boundary

@chuwy chuwy changed the title Attempt to yield across C-call boundary plenary.async.uv: Attempt to yield across C-call boundary Oct 6, 2021
@w0ng
Copy link

w0ng commented Oct 11, 2021

I can reproduce this

NVIM v0.5.1
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/build/config -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/src -I/usr/local/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/build/src/nvim/auto -I/tmp/neovim-20210927-1441-demfsz/neovim-0.5.1/build/include
Compiled by brew@BigSur

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.5.1/share/nvim"

Run :checkhealth for more info

@rcarriga
Copy link

rcarriga commented Dec 9, 2021

Async functions must be called from an async context or with async.run. Calling an async function directly means the current function must be async as well. This is very similar to JS or Python where it is more explicit because it's built-in

local a = require("plenary.async")

-- `read` is an async function
read = function(path)
  local err, fd = a.uv.fs_open(path, "r", 438)
  assert(not err, err)
end

a.run(function() read("mypath") end)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants