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
API: nvim_buf_attach not returning #8634
Comments
What does "no return" mean? Is it blocking ? What client are you using. Provide complete, exact steps, not a description. |
You probably don't want to look at my C++ code, but here is how you can reproduce the issue using node: const { spawn } = require("child_process");
const msgpack = require("msgpack-lite");
const nvim = spawn("nvim", ["--embed"]);
nvim.stdout.on("data", data => {
console.log(msgpack.decode(Buffer.from(data)));
});
nvim.stdin.write(msgpack.encode([0, 0, "nvim_buf_attach", [0, false, {}]])); Results in:
However, const { spawn } = require("child_process");
const msgpack = require("msgpack-lite");
const nvim = spawn("nvim", ["--embed"]);
nvim.stdout.on("data", data => {
// console.log(data);
console.log(msgpack.decode(data));
});
nvim.stdin.write(msgpack.encode([0, 0, "nvim_ui_attach", [1, 1, {}]]));
The last line above ( |
Can't reproduce using the python client.
|
This comment has been minimized.
This comment has been minimized.
If I repeat the call then I see a response.
If I build
then use that build from javascript: const { spawn } = require("child_process");
const msgpack = require("msgpack-lite");
const nvim = spawn("./build/bin/nvim", ["-u", "NONE", "-i", "NONE", "-n", "--embed"], {env: {NVIM_LOG_FILE: 'log'}});
nvim.stdout.on("data", data => {
console.log('stdout: ');
console.log(msgpack.decode(Buffer.from(data)));
});
nvim.stdin.write(msgpack.encode([0, 0, "nvim_buf_attach", [0, false, {}]])); the Nvim log shows that the response was written to the channel:
so the problem (if any) doesn't seem to be at the Nvim RPC level. Note that the notification is written before the response. |
In case it helps, here is my C++ source where I test the nvim API: https://gitlab.com/eidheim/neovim-embed-test. Note that I added a second delay before calling |
@eidheim Is your client prepared to handle notifications while waiting on a response? See my previous comment. |
Yes, the C++ client handles notifications while waiting for a response. |
Can you build with |
@justinmk yes the node client can handle notifications in between request/response, none of the examples are using the node client though. note that node-client currently wraps the call to |
Oops, right. I started with the node client locally, then combined too many thoughts... |
Also fwiw, when building neovim from source (from latest master), the node snippet from @justinmk produces this:
|
I tried the latest master and can confirm that both the node client and C++ client works. That is, the C++ client works if I remove this line: https://gitlab.com/eidheim/neovim-embed-test/blob/master/main.cpp#L60, so there is sadly still some issue here I think. |
@eidheim what nvim version were you testing before ...? Nothing changed in RPC or channel implementation since 0.3.0 was released.
Why would this point to an issue with Nvim? Nvim writes to a buffer. sleep() tickles the OS scheduler. Nvim is single threaded. That c++ client is multithreaded ... |
I used nvim 0.3.0 on MacOS and Arch Linux. To test latest master, I installed neovim-git through Arch Linux AUR using yaourt. The only thing the sleep is doing, is wait a second before writing the |
The problem can be reproduced using node: const { spawn } = require("child_process");
const msgpack = require("msgpack-lite");
const nvim = spawn("nvim", ["--embed"]);
nvim.stdout.on("data", data => {
console.log(msgpack.decode(data));
});
setTimeout(() => {
nvim.stdin.write(msgpack.encode([0, 0, "nvim_buf_attach", [0, false, {}]]));
}, 1000); Outputs:
That is without the result package. |
Couldn't that be a race in You also mentioned:
This hasn't been reported before. We have thousands of RPC tests that depend on the basic functionality of an RPC response. |
The problem with |
I can't follow here, but let me just throw in that I've written benchmarks in rust that embed a neovim instance, and I do not have to wait for the spawn or something like this. I've also not noticed a reply missing (same goes for the lua tests I've written). |
In #8663 @roflcopter4 mentioned that they created another custom nvim client in C. @roflcopter4 can you confirm whether you also observe the behavior in this issue? Specifically, does the (boolean) return value of a RPC call to |
The boolean value being the 6th argument, right? I haven't noticed any kind of problem with that. My hacky "client" is too undeveloped right now to bother distinguishing between expected replies and notifications, so I made it multi-threaded and opened a socket for each thread. One socket, one request, one reply. Neovim always returns promptly, to the correct socket, as expected. |
@eidheim I added a test in https://github.com/neovim/neovim/pull/8672/files#diff-d68045ff8f987ecf323e339fe76df7cdR744 which I think matches the semantics of the steps in #8634 (comment) . |
This test is mostly a demo/reference for: neovim#8634 (comment) so let's not pay a 1s penalty.
This test is mostly a demo/reference for: neovim#8634 (comment) so let's not pay a 1s penalty.
Right now we're in a place where we *should* be able to run integration tests against an embedded neovim (modulo filling the buffer, of course) but the `nvim_buf_attach` call never seems to result in a Response packet. Included in this commit is a unit test demonstrating the issue. See neovim/neovim#8634
For what it's worth I'm also experiencing this issue in my Kotlin project, and can also reproduce it via a node script like those linked above: const { spawn } = require("child_process");
const msgpack = require("msgpack-lite");
console.log("spawning...");
const nvim = spawn("nvim", ["-u", "NONE", "--embed"]);
nvim.stderr.on("data", data => {
console.log("ERR", data);
});
nvim.stdout.on("data", data => {
console.log('stdout: ');
console.log(msgpack.decode(Buffer.from(data)));
});
nvim.stdin.write(msgpack.encode([0, 0, "nvim_buf_attach", [0, false, {}]]));
setTimeout(() => {
console.log("timeout");
process.exit(1);
}, 1500); With nvim
With the latest HEAD (via |
Similarly, #!/usr/bin/env node
const { spawn } = require("child_process");
const msgpack = require("msgpack-lite");
console.log("spawning...");
const nvim = spawn("nvim", ["-u", "NONE", "--embed"]);
nvim.stderr.on("data", data => {
console.log("ERR", data);
});
nvim.stdout.on("data", data => {
console.log('stdout: ');
console.log(msgpack.decode(Buffer.from(data)));
});
nvim.stdin.write(msgpack.encode([0, 0, "nvim_buf_attach", [0, false, {}]]));
setTimeout(() => {
nvim.stdin.write(msgpack.encode([0, 1, "nvim_buf_detach", [0]]));
}, 1000);
setTimeout(() => {
console.log("timeout");
process.exit(1);
}, 2500); results in:
With nvim |
Right now we're in a place where we *should* be able to run integration tests against an embedded neovim (modulo filling the buffer, of course) but the `nvim_buf_attach` call never seems to result in a Response packet. Included in this commit is a unit test demonstrating the issue. See neovim/neovim#8634
When testing the new buffer API functions through
nvim --embed
, I noticed thatnvim_buf_attach
never returns, but an event is fired. Also, when calling for instancenvim_buf_set_lines
, it often returns, but not always.The text was updated successfully, but these errors were encountered: