This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Don't send invalid messages from remote index
ClosedPublic

Authored by kbobyrev on Jul 14 2020, 3:39 PM.

Details

Summary

Remote server should not send messages that are invalid and will cause problems
on the client side. The client should not be affected by server's failures
whenever possible.

Also add more error messages and logs.

Diff Detail

Event Timeline

kbobyrev created this revision.Jul 14 2020, 3:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2020, 3:39 PM
kbobyrev updated this revision to Diff 278008.Jul 14 2020, 3:51 PM

Also do not attempt to use callback on unserialized messages.

kbobyrev updated this revision to Diff 278022.Jul 14 2020, 4:50 PM

Use the same style for elog messages (1-based indexing, message format).

kbobyrev updated this revision to Diff 278086.Jul 15 2020, 12:19 AM

Don't allow empty paths.

Also add more error messages and logs.

I'm not sure about the error-handling strategy here:

  • it's very verbose in the marshalling code. Are we sure it pays for itself? For comparison, the marshalling code for LSP itself silently returns false on error, which is handled at the top level. It's been fine so far.
  • some errors are being logged that are not errors. e.g. it's not an error to drop a symbol because its declaration is in a file outside the index root, that's just expected behavior
  • it's not clear which levels are responsible for logging errors, leaving the possibility that some errors will be logged twice or not at all
  • it's not easy to change if we want a slightly different strategy

I'd suggest leaving out detailed error reporting for now, and reporting at the top level. You may need some mechanism to distinguish invalid vs filtered-out data.
It could be something like a "filtered out" flag that causes the error reporting to be suppressed. There are more design options here if marshalling is a class I think.

clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
72–73

aren't all these placeholders incorrect? first is {0}

90–91

missing definition is perfectly valid, so both the old and new code look wrong here

229

convert, protobuf

245–246

we shouldn't be checking this every time, IndexRoot is fixed for the lifetime of the index so it should be checked once and asserted here.

(Wrapping the marshalling in a class is a nice clean way to do this)

254–255

and here... IndexRoot shouldn't be checked every time

Use the same style for elog messages (1-based indexing, message format).

As far as I can tell, 1-based indexing isn't an option that's available. Where do you see that it is?

kbobyrev marked 4 inline comments as done.Jul 15 2020, 6:11 AM

Also add more error messages and logs.

I'm not sure about the error-handling strategy here:

  • it's very verbose in the marshalling code. Are we sure it pays for itself? For comparison, the marshalling code for LSP itself silently returns false on error, which is handled at the top level. It's been fine so far.
  • some errors are being logged that are not errors. e.g. it's not an error to drop a symbol because its declaration is in a file outside the index root, that's just expected behavior

Can you give an example of this? Missing d

  • it's not clear which levels are responsible for logging errors, leaving the possibility that some errors will be logged twice or not at all
  • it's not easy to change if we want a slightly different strategy

I'd suggest leaving out detailed error reporting for now, and reporting at the top level. You may need some mechanism to distinguish invalid vs filtered-out data.
It could be something like a "filtered out" flag that causes the error reporting to be suppressed. There are more design options here if marshalling is a class I think.

Fair enough, will do. Thanks!

clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
72–73

I think they still work for some reason. Anyway, starting with {0} is OK, I think they're just off in some places.

90–91

Oh, you're right missing definition is indeed OK, but having an invalid one should still be invalid. I guess I should check if it's empty.

kbobyrev updated this revision to Diff 278162.Jul 15 2020, 6:13 AM
kbobyrev marked an inline comment as done.

Small update: resolve a couple of comments.

kbobyrev updated this revision to Diff 278170.Jul 15 2020, 6:56 AM

Use DebugStrings instead of ShortDebugStrings.

kbobyrev planned changes to this revision.Jul 15 2020, 10:25 AM

Wrap marshalling into a class, think about filtering vs failing? I think filtering should be done on the clangd-indexer side and marshalling should deal with valid symbols only and shouldn't have to filter them.

kbobyrev updated this revision to Diff 278682.Jul 17 2020, 2:21 AM
kbobyrev marked 2 inline comments as done.

Refactor marshalling into a class, log errors only on the high level.

kbobyrev updated this revision to Diff 278683.Jul 17 2020, 2:23 AM

Remove (now empty) Marshalling.h file comment.

sammccall accepted this revision.Jul 20 2020, 8:23 AM
sammccall added inline comments.
clang-tools-extra/clangd/index/remote/Client.cpp
71

this is PratabufMarshaller.reset(new...) or just initialize it in the init list

clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
185–191

nit: just if (*From.Definition.FileURI)?

230

potobuf -> protobuf

clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
56–65

why are these needed?

This revision is now accepted and ready to land.Jul 20 2020, 8:23 AM
kbobyrev updated this revision to Diff 279447.Jul 21 2020, 2:03 AM
kbobyrev marked 5 inline comments as done.

Address post-LGTM comments, rebase on top of HEAD.

This revision was automatically updated to reflect the committed changes.