From 9cf2ef84b7b25e0b41a974a2fb33dc0649d3403b Mon Sep 17 00:00:00 2001 From: nick-linux8 Date: Fri, 13 Mar 2026 11:43:24 -0400 Subject: [PATCH] Added Better Handling In Event Dispatcher Function (#1980) --- core/internal/server/wlcontext/context.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/internal/server/wlcontext/context.go b/core/internal/server/wlcontext/context.go index c7d0aa05..9bbb30aa 100644 --- a/core/internal/server/wlcontext/context.go +++ b/core/internal/server/wlcontext/context.go @@ -2,10 +2,10 @@ package wlcontext import ( "fmt" + "golang.org/x/sys/unix" "os" "sync" - - "golang.org/x/sys/unix" + "time" "github.com/AvengeMedia/DankMaterialShell/core/internal/errdefs" "github.com/AvengeMedia/DankMaterialShell/core/internal/log" @@ -123,6 +123,9 @@ func (sc *SharedContext) eventDispatcher() { {Fd: int32(sc.wakeR), Events: unix.POLLIN}, } + consecutiveErrors := 0 + const maxConsecutiveErrors = 20 + for { sc.drainCmdQueue() @@ -153,9 +156,19 @@ func (sc *SharedContext) eventDispatcher() { } if err := ctx.Dispatch(); err != nil && !os.IsTimeout(err) { - log.Errorf("Wayland connection error: %v", err) - return + consecutiveErrors++ + log.Warnf("Wayland connection error (%d/%d): %v", consecutiveErrors, maxConsecutiveErrors, err) + + if consecutiveErrors >= maxConsecutiveErrors { + log.Errorf("Fatal: Wayland connection unrecoverable after %d attempts. Exiting dispatcher.", maxConsecutiveErrors) + return + } + + time.Sleep(100 * time.Millisecond * time.Duration(consecutiveErrors)) + continue } + + consecutiveErrors = 0 } }