Use buffered channels and ring-buffer logic when processing console data

This change fixes pterodactyl/panel#3921 by implementing logic to drop the oldest message in a channel and push the newest message onto the channel when the channel buffer is full.

This is distinctly different than the previous implementation which just dropped the newest messages, leading to confusing behavior on the client side when a large amount of data was sent over the connection.

Up to 10ms per channel is allowed for blocking before falling back to the drop logic.
This commit is contained in:
Dane Everitt
2022-01-30 10:55:45 -05:00
parent 68d4fb454f
commit fab88a380e
3 changed files with 93 additions and 21 deletions

View File

@@ -89,8 +89,8 @@ func (h *Handler) listenForServerEvents(ctx context.Context) error {
defer cancel()
eventChan := make(chan events.Event)
logOutput := make(chan []byte)
installOutput := make(chan []byte)
logOutput := make(chan []byte, 8)
installOutput := make(chan []byte, 4)
h.server.Events().On(eventChan, e...)
h.server.Sink(server.LogSink).On(logOutput)
h.server.Sink(server.InstallSink).On(installOutput)