Skip to content

Fix race condition in named pipe server causing missed link clicks#217

Open
AaronFeledy wants to merge 1 commit intoU-C-S:mainfrom
AaronFeledy:fix/named-pipe-race-condition
Open

Fix race condition in named pipe server causing missed link clicks#217
AaronFeledy wants to merge 1 commit intoU-C-S:mainfrom
AaronFeledy:fix/named-pipe-race-condition

Conversation

@AaronFeledy
Copy link

@AaronFeledy AaronFeledy commented Jan 28, 2026

Problem

When Hurl runs minimized to the system tray, clicking a link sometimes does nothing on the first click, but works on the second click. The tray service hasn't crashed—it just doesn't respond to the first invocation.

Root Cause

A race condition exists in the named pipe server communication between the Launcher and BrowserSelector:

  1. The pipe server handles a connection and disposes the pipe
  2. The loop restarts and creates a new pipe instance
  3. Between dispose and recreation, no pipe exists
  4. If the Launcher connects during this window, it falls back to spawning Hurl.exe
  5. The spawned process signals the EventWaitHandle, which only shows the window—the URL is lost

Solution

Implement overlapping named pipe server instances that ensure at least one listener is always ready:

  • Maintain 2-3 concurrent pipe listeners at all times
  • When a connection is received, spawn a replacement listener before processing
  • Use proper async/await instead of .Wait() anti-pattern
  • Add 5-second read timeout to prevent hung connections
  • Remove EventWaitHandle (no longer needed with robust pipe server)

Changes

  • New: Source/Hurl.BrowserSelector/Services/NamedPipeUrlReceiver.cs - Encapsulated pipe server with overlapping listener pattern
  • Modified: Source/Hurl.BrowserSelector/App.xaml.cs - Use new service, remove old pipe server and EventWaitHandle code

Fixes #202

@AaronFeledy AaronFeledy force-pushed the fix/named-pipe-race-condition branch 3 times, most recently from a4cc7ad to 4e606cb Compare January 28, 2026 14:19
@U-C-S
Copy link
Owner

U-C-S commented Jan 28, 2026

Thanks for the PR. Will have a look later this week

When Hurl runs minimized to tray, the first link click is sometimes
ignored while subsequent clicks work. This is caused by a race condition
in the named pipe server: after handling a connection, the pipe is
disposed before a new one is created, leaving a brief window where no
pipe exists. If the Launcher connects during this window, the URL is lost.

Fix by implementing overlapping pipe server instances that ensure at
least one listener is always ready. When a connection is received, a
replacement listener spawns immediately before processing begins.

Changes:
- Add NamedPipeUrlReceiver service with overlapping listener pattern
- Use proper async/await instead of .Wait() anti-pattern
- Remove EventWaitHandle (no longer needed with robust pipe server)
- Add 5-second read timeout to prevent hung connections
@AaronFeledy AaronFeledy force-pushed the fix/named-pipe-race-condition branch from 4e606cb to 24b2aee Compare January 28, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need to click on a link twice to get Hurl to appear

2 participants