From a8ce516a6471ab1bd961fca61766dbe3fb2cc2f1 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 26 Feb 2021 23:16:40 +0100 Subject: [PATCH] Prevent system crash by too fast executions Signed-off-by: Knut Ahlers --- cmd/streamdeck/display_exec.go | 9 ++++++++- cmd/streamdeck/display_pulsevolume.go | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/streamdeck/display_exec.go b/cmd/streamdeck/display_exec.go index ac83f26..21440e1 100644 --- a/cmd/streamdeck/display_exec.go +++ b/cmd/streamdeck/display_exec.go @@ -114,7 +114,14 @@ func (d displayElementExec) Display(ctx context.Context, idx int, attributes att } func (d displayElementExec) NeedsLoop(attributes attributeCollection) bool { - return attributes.Interval > 0 + if attributes.Interval > 0 && attributes.Interval < 100*time.Millisecond { + log.WithFields(log.Fields{ + "tpye": "exec", + "interval": attributes.Interval, + }).Warn("Ignoring interval below 100ms") + } + + return attributes.Interval > 100*time.Millisecond } func (d *displayElementExec) StartLoopDisplay(ctx context.Context, idx int, attributes attributeCollection) error { diff --git a/cmd/streamdeck/display_pulsevolume.go b/cmd/streamdeck/display_pulsevolume.go index c551e3d..8ce8f5f 100644 --- a/cmd/streamdeck/display_pulsevolume.go +++ b/cmd/streamdeck/display_pulsevolume.go @@ -118,8 +118,14 @@ func (d displayElementPulseVolume) NeedsLoop(attributes attributeCollection) boo func (d *displayElementPulseVolume) StartLoopDisplay(ctx context.Context, idx int, attributes attributeCollection) error { interval := time.Second - if attributes.Interval > 0 { + if attributes.Interval > 100*time.Millisecond { interval = attributes.Interval + } else if attributes.Interval > 0 { + log.WithFields(log.Fields{ + "tpye": "pulsevolume", + "idx": idx, + "interval": attributes.Interval, + }).Warn("Ignoring interval below 100ms") } go func() {