[GH-ISSUE #322] Add auto restart client by return error emulation server: not responding. #170

Open
opened 2026-05-05 22:12:27 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @F1st3K on GitHub (Oct 7, 2025).
Original GitHub issue: https://github.com/feschber/lan-mouse/issues/322

Sometime i have a problem, connection is dissconected by error view^

[2025-10-07T17:15:46Z WARN  lan_mouse::emulation] releasing keys: 192.168.0.188:44609 not responding!

And i have work around for it (windows client)

Its powershell script, its rerun client by error in stdout

# =============================
# LAN-Mouse Watchdog (clean)
# =============================

$LanMousePath = "C:\Users\kostinnik\Documents\lan\lan-mouse.exe"
$ErrorPattern = "not responding|network error|connection reset|os error 10040"

function Log { param($msg) ; Write-Host $msg }

$Global:LMProcess = $null
$Global:RestartNeeded = $false

function Start-LanMouse {
    if ($Global:LMProcess) {
        try { $Global:LMProcess.Kill() } catch {}
        $Global:LMProcess.Dispose()
        $Global:LMProcess = $null
    }

    # remove prev event subcription
    Get-EventSubscriber | Where-Object {$_.SourceIdentifier -in @("LMOut","LMErr")} | Unregister-Event

    $startInfo = New-Object System.Diagnostics.ProcessStartInfo
    $startInfo.FileName = $LanMousePath
    $startInfo.Arguments = "daemon"
    $startInfo.RedirectStandardOutput = $true
    $startInfo.RedirectStandardError  = $true
    $startInfo.UseShellExecute = $false
    $startInfo.CreateNoWindow = $true

    $proc = New-Object System.Diagnostics.Process
    $proc.StartInfo = $startInfo
    $proc.Start() | Out-Null
    $proc.BeginOutputReadLine()
    $proc.BeginErrorReadLine()
    $Global:LMProcess = $proc

    # stdout event
    Register-ObjectEvent -InputObject $proc -EventName OutputDataReceived -SourceIdentifier LMOut -Action {
        if ($EventArgs.Data) {
            Log "$($EventArgs.Data)"
            if ($EventArgs.Data -match $ErrorPattern) {
                Log "[!] Error detected -> scheduling restart"
                $Global:RestartNeeded = $true
            }
        }
    }

    # stderr event
    Register-ObjectEvent -InputObject $proc -EventName ErrorDataReceived -SourceIdentifier LMErr -Action {
        if ($EventArgs.Data) {
            Log "$($EventArgs.Data)"
            if ($EventArgs.Data -match $ErrorPattern) {
                Log "[!] Error detected -> scheduling restart"
                $Global:RestartNeeded = $true
            }
        }
    }

    Log "✅ lan-mouse started."
}


try {
    # основной код Watchdog
    Start-LanMouse
    Log "Watchdog started. Press Ctrl+C to stop."
    while ($true) {
        Start-Sleep -Milliseconds 500
        if ($Global:RestartNeeded) {
            Log "[!] Restarting lan-mouse..."
            Start-LanMouse
            $Global:RestartNeeded = $false
        }

        if ($Global:LMProcess -and $Global:LMProcess.HasExited) {
            Log "[!] lan-mouse crashed. Restarting..."
            Start-LanMouse
        }
    }
}
finally {
    # cleanup при выходе скрипта
    Log "🛑 Watchdog stopping. Killing lan-mouse..."
    if ($Global:LMProcess) {
        try { $Global:LMProcess.Kill() } catch {}
    }
}

Maybe add this feature to main project?

Originally created by @F1st3K on GitHub (Oct 7, 2025). Original GitHub issue: https://github.com/feschber/lan-mouse/issues/322 Sometime i have a problem, connection is dissconected by error view^ ``` [2025-10-07T17:15:46Z WARN lan_mouse::emulation] releasing keys: 192.168.0.188:44609 not responding! ``` And i have work around for it (windows client) Its powershell script, its rerun client by error in stdout ```powershell # ============================= # LAN-Mouse Watchdog (clean) # ============================= $LanMousePath = "C:\Users\kostinnik\Documents\lan\lan-mouse.exe" $ErrorPattern = "not responding|network error|connection reset|os error 10040" function Log { param($msg) ; Write-Host $msg } $Global:LMProcess = $null $Global:RestartNeeded = $false function Start-LanMouse { if ($Global:LMProcess) { try { $Global:LMProcess.Kill() } catch {} $Global:LMProcess.Dispose() $Global:LMProcess = $null } # remove prev event subcription Get-EventSubscriber | Where-Object {$_.SourceIdentifier -in @("LMOut","LMErr")} | Unregister-Event $startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo.FileName = $LanMousePath $startInfo.Arguments = "daemon" $startInfo.RedirectStandardOutput = $true $startInfo.RedirectStandardError = $true $startInfo.UseShellExecute = $false $startInfo.CreateNoWindow = $true $proc = New-Object System.Diagnostics.Process $proc.StartInfo = $startInfo $proc.Start() | Out-Null $proc.BeginOutputReadLine() $proc.BeginErrorReadLine() $Global:LMProcess = $proc # stdout event Register-ObjectEvent -InputObject $proc -EventName OutputDataReceived -SourceIdentifier LMOut -Action { if ($EventArgs.Data) { Log "$($EventArgs.Data)" if ($EventArgs.Data -match $ErrorPattern) { Log "[!] Error detected -> scheduling restart" $Global:RestartNeeded = $true } } } # stderr event Register-ObjectEvent -InputObject $proc -EventName ErrorDataReceived -SourceIdentifier LMErr -Action { if ($EventArgs.Data) { Log "$($EventArgs.Data)" if ($EventArgs.Data -match $ErrorPattern) { Log "[!] Error detected -> scheduling restart" $Global:RestartNeeded = $true } } } Log "✅ lan-mouse started." } try { # основной код Watchdog Start-LanMouse Log "Watchdog started. Press Ctrl+C to stop." while ($true) { Start-Sleep -Milliseconds 500 if ($Global:RestartNeeded) { Log "[!] Restarting lan-mouse..." Start-LanMouse $Global:RestartNeeded = $false } if ($Global:LMProcess -and $Global:LMProcess.HasExited) { Log "[!] lan-mouse crashed. Restarting..." Start-LanMouse } } } finally { # cleanup при выходе скрипта Log "🛑 Watchdog stopping. Killing lan-mouse..." if ($Global:LMProcess) { try { $Global:LMProcess.Kill() } catch {} } } ``` Maybe add this feature to main project?
Author
Owner

@F1st3K commented on GitHub (Oct 7, 2025):

e46fe60b3e/src/emulation.rs (L179-L187)

<!-- gh-comment-id:3377930881 --> @F1st3K commented on GitHub (Oct 7, 2025): https://github.com/feschber/lan-mouse/blob/e46fe60b3e24be83de38701faa99a4fbd9186f08/src/emulation.rs#L179-L187
Author
Owner

@feschber commented on GitHub (Oct 7, 2025):

I would prefer to fix this within lan-mouse. Technically you should be able to reconnect automatically? Does that not work?

<!-- gh-comment-id:3378734974 --> @feschber commented on GitHub (Oct 7, 2025): I would prefer to fix this within lan-mouse. Technically you should be able to reconnect automatically? Does that not work?
Author
Owner

@F1st3K commented on GitHub (Oct 7, 2025):

No, now it's not work. We don't have automatic rerun for it.

<!-- gh-comment-id:3378997982 --> @F1st3K commented on GitHub (Oct 7, 2025): No, now it's not work. We don't have automatic rerun for it.
Author
Owner

@Geobert commented on GitHub (Mar 19, 2026):

I have the issue as well and looking at the code, it seems that we disconnect (and controls are stuck on slave)

self.emulation_proxy.remove(addr);
self.event_tx.send(EmulationEvent::Disconnected { addr }).expect("channel closed");

Maybe some kind of retry before disconnecting?

<!-- gh-comment-id:4090261725 --> @Geobert commented on GitHub (Mar 19, 2026): I have the issue as well and looking at the code, it seems that we disconnect (and controls are stuck on slave) ``` self.emulation_proxy.remove(addr); self.event_tx.send(EmulationEvent::Disconnected { addr }).expect("channel closed"); ``` Maybe some kind of retry before disconnecting?
Author
Owner

@Geobert commented on GitHub (Mar 19, 2026):

@F1st3K does this start with elevated privilege to workaround #127 ?

<!-- gh-comment-id:4090270113 --> @Geobert commented on GitHub (Mar 19, 2026): @F1st3K does this start with elevated privilege to workaround #127 ?
Author
Owner

@F1st3K commented on GitHub (Mar 19, 2026):

@Geobert, i dont have a admin permision on work laptop with windows.

<!-- gh-comment-id:4091136599 --> @F1st3K commented on GitHub (Mar 19, 2026): @Geobert, i dont have a admin permision on work laptop with windows.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/lan-mouse#170
No description provided.