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

(GH-11) Refactor transport layer and fix STDIO server #9

Merged
merged 3 commits into from
Apr 24, 2018

Conversation

glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Apr 18, 2018

Previously the different transport types, TCP and STDIO, were very closely coupled which made debugging and maintaining them difficult. This commit changes the relationships between the server, client connection, message handler and message router classes/objects to be much looser and can therefore be defined/instantiated easier at run time;


A new SimpleSTDIOServer class was created which implements a blocking STDIO pipe reader. It also implements an async stop method which be called when the Language Server wishes to exit.


Previously if an invalid logfile location was specified e.g. C:\ or a missing parent directory, the service (Language or Debug Server) would error. This is undesired as a bad log file should not cause a catastrophic failure. This commit modifies the logging so that an error occurs when the log file is created it, the error is sent to STDERR, and service continues but with logging disabled.

…ling

Previously the different transport types, TCP and STDIO, were very closely
coupled which made debugging and maintaining them difficult.  This commit
changes the relationships between the server, client connection, message
handler and message router classes/objects to be much looser and can therefore
be defined/instantiated easier at run time;

New object model

- (Transport Server) creates a (Client Connection object) per incoming connection
- Each (Client Connection object) creates a (Handler object)
- Each (Handler object) creates a (Message Router object)

Therefore the Message Router can create messages which traverse back down the
object chain and is eventually emitted by the Transport Server.

This model should apply whether it is a STDIO or TCP transport

* The JSON Handler no longer inherits the TCP Server Connection, but a generic
  SimpleServerConnectionHandler which has some base methods.  The message
  router object is now assigned via the message_router methods, which can be
  passed in via the initializer, or defaults to an instance of the
  PuppetDebugServer::MessageRouter class.

  The client connection object is expected to implement the
  SimpleServerConnectionBase "interface" and passedv in via the Handler
  initializer.

* The Message Router no longer inherits from the JSON handler, but has a
  json_handler method.  It is assumed the Handler will set this when it creates
  an instance of the Router

* A new SimpleSTDIOServerConnection object has been created which implements the
  base SimpleServerConnectionBase object.  This object is the concrete
  implementation of connection over the STDIO transport

* The TCP Server Connection now inherits from the SimpleServerConnectionBase
  object and tracks the originating TCP Server object and socket via the
  initializer

* PuppetLanguageServer was modified to use the new STDIO connection type and
  use the JSON Handler instead of the MessageRouter

* The document_type method was moved from the MessageRouter code to the
  DocumentStore module.  This made more sense and means that we don't need to
  create an entire Message Router object to do a simple static document type
  check

* The validation queue was modified with the new namespace of the document_type
  static method

* Tests were modified for the new object hierarchy
Previously the transport layer was refactored but did not implement a STDIO
server.  This commit

* Concretely implements a STDIO connection.  The old references to a socket are
  removed

* A new SimpleSTDIOServer class was created which implements a blocking STDIO
  pipe reader.  It also implements an async stop method which be called when
  the Language Server wishes to exit.

* The server disables verbose logging (e.g. Kernel.warn) which would contaminate
  STDIO streams

* The server uses binary mode which stops ruby being helpful and injecting CRLF
  unnecessarily.

* Adds a logging destination which diverts any puppet logging into the
  language server log otherwise this would contaminate the STDIO streams
Previously if an invalid logfile location was specified e.g. C:\ or a missing
parent directory, the service (Language or Debug Server) would error.  This is
undesired as a bad log file should not cause a catastrophic failure.  This
commit modifies the logging so that an error occurs when the log file is
created it, the error is sent to STDERR, and service continues but with logging
disabled.

This commit also flushes the log file on each write if needed.  This is required
as OS buffering makes real time debugging very difficult.
@glennsarti glennsarti changed the title {WIP} Refactor transport layer (GH-11) Refactor transport layer and fix STDIO server Apr 19, 2018
@glennsarti glennsarti requested a review from jpogran April 19, 2018 07:43
@glennsarti
Copy link
Contributor Author

Ready for merge

Copy link
Contributor

@jpogran jpogran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a review with @glennsarti today. 👍

@jpogran jpogran merged commit a3d49e6 into puppetlabs:master Apr 24, 2018
@glennsarti glennsarti added this to the 0.11.0 milestone Apr 25, 2018
@glennsarti glennsarti deleted the refactor-transport-layer branch May 4, 2018 06:31
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.

2 participants