-
Notifications
You must be signed in to change notification settings - Fork 23
[RFC] corrupted msgpack streams are printed to screen and/or saved #38
base: master
Are you sure you want to change the base?
Conversation
It seems the |
nvim/msgpack_rpc_stream.lua
Outdated
local a, b, c, d, e = self._session:receive(data, pos) | ||
return {a, b, c, d, e} | ||
end | ||
local status, rv = pcall(helper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this:
status, type, id_or_cb, method_or_error, args_or_result, pos =
pcall(self._session:receive, data, pos)
id_or_cb, method_or_error, args_or_result, pos
will all be nil
if the call fails. Otherwise they'll have the return values.
type
will be the error message on failure, otherwise it will have the type
return value.
nvim/msgpack_rpc_stream.lua
Outdated
badfile:write(data) | ||
badfile:close() | ||
|
||
-- build a printable representation of the bad part of the string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/helpers.lua
has a hexdump()
function. Might be good enough to paste it into lua-client and use it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I'll copy-paste hexdump into the file. BTW is there a more reasonable place for me to save the full data contents (instead of ./msgpack-fail
?), and is there an easy way I can turn that behaviour off in CI where we'll never be able to get at the saved data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a more reasonable place for me to save the full data contents (instead of ./msgpack-fail?), a
What's wrong with that? This situation should almost never happen. So it doesn't matter for CI or elsewhere.
nvim-client-0.1.0-1.rockspec
Outdated
@@ -1,8 +1,8 @@ | |||
package = 'nvim-client' | |||
version = '0.1.0-1' | |||
source = { | |||
url = 'https://github.com/neovim/lua-client/archive/' .. version .. '.tar.gz', | |||
dir = 'lua-client-' .. version, | |||
url = 'git://github.com/phodge/lua-client.git', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this should not be the .tar.gz
form? I don't know much about luarocks , I'm just basing this on the old code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this form on one of the luarocks wiki pages, but it'll have to get reverted before I merge my branch anyway.
@justinmk: frustratingly my mac is passing all the tests again today so I've had to split my focus onto some of the other issues while I wait for Travis to rerun the OSX tests for me. However the good news is - I've added some additional debug output to the lua-client and it now looks like the OSX bug is caused by some extra data coming in on the end of a "redraw" RPC notification. (See https://api.travis-ci.org/v3/job/397526419/log.txt - search for "invalid msgpack" and scroll up a little). I'd like to get your opinion on the debug output and implementation in this PR - if there's anything you'd like changed before this gets merged in. |
Are you sure it's extra data? Or just malformed somehow? I can't tell from looking at the bytes:
Now we need a way to make that human-readable :) (is that what your old code did...?) |
I'm 55% certain it's extra data, because if you look at the lua mpack C code the error gets raised when the session receive function realises that the value it just unpacked isn't a notification, a request, or a response. As for human-readable, I guess that depends what you prefer. I liked the previous solution of using |
Well, the table above has hex codes... but feel free to add the other logic, then keep and show both representations. Don't need to be tidy now. |
If
None of those patterns show up in the dump, so we're in the middle of a single message.
As noted, the method from the previous The first two arrays are the tail end of a previous "put" event, Taking a look at The question then is why the "redraw" notification is being broken up instead of handled as a single message. |
Hmm, It seems like we probably need to do two things.
|
@jamessan: Thanks for the extra guidance, I've managed to reproduce the exact error on linux now. It happens when read_start() gets the data split into at least two parts, where the first part is exactly 8192 bytes. FYI the |
38b0fb7
to
e343477
Compare
@justinmk: I've rebased this branch to tidy up the commits and remove the rockspec hackery. It should be good to merge. |
Functions and tables can't be formatted using %s
0a472e6
to
3dc2c48
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI the mpack.Session instance is responsible for storing the incomplete data internally, so there's no reason to handle it inside msgpack_rpc_stream.lua. But for some reason, when mpack.Session.receive() gets the first 8192 bytes of the redraw notification, it returns an incomplete object rather than recognising it only has part of the data and waiting for more to arrive.
@phodge if that's the case, then it is probably a bug in libmpack and if so must be fixed there. Can you save the blob causing this error so I can write a test in libmpack?
Hi @tarruda: I can't rerun the test right now, but you should still be able to apply the patch in neovim/neovim#8102 (comment) to reproduce. |
Also, is there anything else I need to fix on this PR before it can be merged? |
So all I have to do is apply that patch and run neovim tests locally? Is there a specific test which is more likely to trigger?
No, LGTM |
@tarruda: IIRC it was |
Was this intended to be merged as-is? I thought it was just being used for debugging. I'm not sure we should be printing the debug messages and writing a file to disk when we get an incomplete message. |
Agreed, I thought this was going to be merged in order to obtain the blobs from the tests, but I guess we can simply change neovim build system to download from @phodge 's branch |
We do want to merge this in some form, so that it works for every PR, automatically. Writing a hint file maybe is the only way. |
Could the printing/saving be turned on via a debug flag or environment
variable perhaps? I don't think anyone wants to have to manually patch lua
source to debug a msgpack stream, and installing an alternate git branch
via LuaRocks/RockSpec is not simple either.
|
@justinmk applying your patch actually results in an invalid msgpack-rpc payload being sent After applying @phodge patch and running @phodge can you reproduce the error easily in your computer? If so and you manage to save it in a file, please post it somewhere so I can debug libmpack locally. |
Forgive this novice Lua code ... this is my attempt at getting the lua client to print corrupted msgpack streams to screen. The entire blob is also saved to disk to aid local debugging. Related to neovim issue neovim/neovim#8102, and neovim PR neovim/neovim#8638