Skip to content

Conversation

@ferdinand-beyer
Copy link
Contributor

@ferdinand-beyer ferdinand-beyer commented Oct 24, 2023

Fixes #41

This approach closes the output channel when writing a message to the output stream fails for any reason. Expected reasons are:

  • I/O exception
  • JSON encoding exception

This will prevent the server from blocking forever on a channel that has no more consumers. Instead, messages will be dropped.

We expect that the client will send an exit message and eventually close the connection. This will close the server's input channel and allow it to terminate.

(write-message writer msg)
(catch Throwable e
(async/close! messages)
(throw e)))
Copy link
Member

Choose a reason for hiding this comment

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

I suppose this throw is enough to the developer know this was a JSON parse exception or something right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it depends a bit on the setup. Because this runs within a core.async/thread, the exception is probably given to the thread's uncaught exception handler. I think the default one will dump the stack trace to stderr, but many logging frameworks will allow to install a custom handler to log those. Definitely something people should do.

As a library, I figured we should stay un-opinionated here and just throw.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, agreed

Copy link
Member

@ericdallo ericdallo left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@mainej mainej left a comment

Choose a reason for hiding this comment

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

Seems like a practical solution. One suggestion below, but looks good!

@ericdallo ericdallo merged commit 2825463 into clojure-lsp:master Oct 28, 2023
@ericdallo
Copy link
Member

Thank you!

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.

Corrupted state when JSON write fails

3 participants