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

fix: crash on receiving an LSP message in "stream" mode #1710

Merged
merged 1 commit into from
Nov 23, 2020

Conversation

rchl
Copy link
Contributor

@rchl rchl commented Nov 4, 2020

Don't write log messages to stdout in "stream" mode. stdout is reserved
for communicating with the LSP client in the "stream" mode. Write all
types of log messages to stderr.

Fixes LSP server crashing on the first message it receives (or maybe
LSP client closing it because it received an invalid response).

Also:

  • the callback to socket.write() was always logging the "err" parameter
    even if there was undefined which caused spurious lines in the
    console. Only actually log that if "err" is truthy.
  • Avoid too many newlines at the end of the log message as that also
    causes spurious empty lines in the log and the console.
  • Gracefully handle the case when the response for "workspace/configuration"
    returns a null value. Those configuration options have sane defaults
    and don't need to be present.
  • The Logger._stream property was removed as it was unused.

Resolves #1708

@codecov
Copy link

codecov bot commented Nov 4, 2020

Codecov Report

Merging #1710 (f28ff4e) into main (9ee365c) will increase coverage by 1.45%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1710      +/-   ##
==========================================
+ Coverage   63.80%   65.26%   +1.45%     
==========================================
  Files          86       86              
  Lines        4694     4698       +4     
  Branches     1258     1261       +3     
==========================================
+ Hits         2995     3066      +71     
+ Misses       1441     1382      -59     
+ Partials      258      250       -8     
Impacted Files Coverage Δ
...ages/graphql-language-service-server/src/Logger.ts 96.77% <90.00%> (+96.77%) ⬆️
...ql-language-service-server/src/MessageProcessor.ts 60.23% <100.00%> (+9.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ee365c...f28ff4e. Read the comment docs.

@acao
Copy link
Member

acao commented Nov 5, 2020

fantastic, thank you!

@rchl
Copy link
Contributor Author

rchl commented Nov 5, 2020

There might be an issue with trim() call that I've added. Let me do a small fixup.

@rchl
Copy link
Contributor Author

rchl commented Nov 5, 2020

Fixed with the latest commit. Feel free to squash all commits on merging.

(Also noticed that when schema server is not running, that will trigger an unhandled exception but I'll handle that in a separate PR).

Don't write log messages to stdout in "stream" mode. stdout is reserved
for communicating with the LSP client in the "stream" mode. Write all
types of log messages to stderr.

Fixes LSP server crashing on the first message it receives (or maybe
LSP client closing it because it received an invalid response).

Also:
 - the callback to socket.write() was always logging the "err" parameter
   even if there was undefined which caused spurious lines in the
   console. Only actually log that if "err" is truthy.
 - Avoid too many newlines at the end of the log message as that also
   causes spurious empty lines in the log and the console.
 - Gracefully handle the case when the response for "workspace/configuration"
   returns a null value. Those configuration options have sane defaults
   and don't need to be present.
 - The Logger._stream property was removed as it was unused.

Resolves graphql#1708
@acao
Copy link
Member

acao commented Nov 23, 2020

fabulous work, looks good to merge. thanks for this!

@acao acao merged commit 1238075 into graphql:main Nov 23, 2020
@rchl rchl deleted the fix/stream-mode branch November 23, 2020 18:13
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

Successfully merging this pull request may close these issues.

LSP server broken when using stream method
2 participants