Skip to content

Fix duplicate instances on toast click when IPC forward times out#5184

Merged
Gabriel Dufresne (GabrielDuf) merged 3 commits into
mainfrom
fix/single-instance-forward-timeout
Jul 23, 2026
Merged

Fix duplicate instances on toast click when IPC forward times out#5184
Gabriel Dufresne (GabrielDuf) merged 3 commits into
mainfrom
fix/single-instance-forward-timeout

Conversation

@GabrielDuf

Copy link
Copy Markdown
Contributor

This pull request refactors and improves the single-instance handling logic in SingleInstanceRedirector.cs to make inter-process communication via named pipes more robust and responsive. The main improvements are around error handling, non-blocking connection management, and timeouts for both reading and forwarding arguments between instances.

Named pipe connection handling improvements:

  • The listener now uses NamedPipeServerStream.MaxAllowedServerInstances and asynchronous options, allowing multiple incoming connections to be handled without blocking the main thread. Each client connection is processed off-thread, so a slow or stuck client cannot prevent new connections. (src/UniGetUI.Avalonia/Infrastructure/SingleInstanceRedirector.cs)
  • Added a new HandleConnection method that reads pipe input asynchronously with a timeout (ReadTimeout), preventing clients that never send EOF from blocking the server. Errors are logged without crashing the listener. (src/UniGetUI.Avalonia/Infrastructure/SingleInstanceRedirector.cs)

Timeouts and retry logic:

  • Introduced ForwardBudget and ReadTimeout constants to bound how long the process will attempt to forward arguments to the first instance and how long it will wait for pipe reads, respectively. (src/UniGetUI.Avalonia/Infrastructure/SingleInstanceRedirector.cs)
  • The TryForwardToFirstInstance method now retries connecting and sending arguments to the first instance until the ForwardBudget expires, logging the last error if unsuccessful. (src/UniGetUI.Avalonia/Infrastructure/SingleInstanceRedirector.cs)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves single-instance IPC resilience for Avalonia launches.

Changes:

  • Handles concurrent named-pipe connections asynchronously.
  • Adds read and forwarding timeouts with retry logic.
  • Prevents stalled clients from blocking subsequent activations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/UniGetUI.Avalonia/Infrastructure/SingleInstanceRedirector.cs Outdated
Comment thread src/UniGetUI.Avalonia/Infrastructure/SingleInstanceRedirector.cs Outdated
@GabrielDuf
Gabriel Dufresne (GabrielDuf) merged commit 12957a0 into main Jul 23, 2026
5 checks passed
@GabrielDuf
Gabriel Dufresne (GabrielDuf) deleted the fix/single-instance-forward-timeout branch July 23, 2026 15:43
@GabrielDuf Gabriel Dufresne (GabrielDuf) linked an issue Jul 23, 2026 that may be closed by this pull request
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Since few release, UNIGET run multiple instances

3 participants