TypeCobolTeam / TypeCobol

TypeCobol is an Incremental Cobol parser for IBM Enterprise Cobol 6 for zOS syntax. TypeCobol is also an extension of Cobol 85 language which can then be converted to Cobol85.
Other
78 stars 26 forks source link

Track LanguageServer exceptions #2668

Open fm-117 opened 1 week ago

fm-117 commented 1 week ago

To improve monitoring of our LanguageServer, we have to introduce some telemetry events for server exceptions. This issues encompasses multiple goals :

fm-117 commented 1 week ago

LoggingSystem is also part of the 'problem', we should improve the current implementation by using an AutoResetEvent instead of a periodic poll.

fm-117 commented 1 week ago

Current LS observations:

We should cover all threads working simultaneously in the server to ensure the application won't crash and also track all exceptions. In our LanguageServer, we have at most 5 concurrent threads:

  1. main thread is responsible for reading the command-line options, starting the worker thread, and listening to incoming messages and putting them on the queue
  2. worker thread is responsible for reading the pending messages on the queue and process them one at a time, in order
  3. background compilation thread is responsible for refreshing the AST of the current document 750ms after the last didChange event received
  4. logger thread is not part of LS but is activated by LoggingSystem, it is responsible for performing logging actions
  5. message sender thread is responsible for sending messages to client. While it could be done by worker thread, the current implementation delegates the actual sending on another thread

Following table states how each thread is protected against crash:

Thread Status TODO
main not protected directly, but a crash will be caught by UnhandledException event Check if some exceptions currently caught can be notified
worker All client messages are covered by 2 catch blocks, each having a notify mechanism, auto-messages are covered too Simplify code ? Avoid redundant catch blocks ?
background compilation Covered by a can block + Notify
logger Not covered but it's ok, logging is secondary and should be considered as safe Improve implementation using AutoResetEvent
message sender Not covered The ThreadBody does not have its own try-catch block, waiting the sending task is alsso unsafe

Unlike other locations, AppDomain.UnhandledException denotes a fatal problem: a window/showMessage should be sent to the client to signal the server has crashed.

fm-117 commented 1 day ago

Proposal for event serialization:

        public class TelemetryEvent
        {
            public string type;
            public Dictionary<string, string> data;
        }

For example, for an exception, data would contain: