Add Goodbye message to ensure plugins exit when they are no longer needed (#12014)

# Description

This fixes a race condition where all interfaces to a plugin might have
been dropped, but both sides are still expecting input, and the
`PluginInterfaceManager` doesn't get a chance to see that the interfaces
have been dropped and stop trying to consume input.

As the manager needs to hold on to a writer, we can't automatically
close the stream, but we also can't interrupt it if it's in a waiting to
read. So the best solution is to send a message to the plugin that we
are no longer going to be sending it any plugin calls, so that it knows
that it can exit when it's done.

This race condition is a little bit tricky to trigger as-is, but can be
more noticeable when running plugins in a tight loop. If too many plugin
processes are spawned at one time, Nushell can start to encounter "too
many open files" errors, and not be very useful.


# User-Facing Changes


# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

I will need to add `Goodbye` to the protocol docs
This commit is contained in:
Devyn Cairns
2024-02-28 18:41:22 -08:00
committed by GitHub
parent 345edbbe10
commit ab08328a30
6 changed files with 80 additions and 3 deletions

View File

@ -217,6 +217,8 @@ def write_error(id, msg, span=None):
def handle_input(input):
if "Hello" in input:
return
elif input == "Goodbye":
return
elif "Call" in input:
[id, plugin_call] = input["Call"]
if "Signature" in plugin_call: