- Version: 0.5.2
- .NET: 10.0.302 SDK
- Target: win-x64 (Windows 11)
On some of our Windows machines, app startup was noticeably slow. Replacing localhost with 127.0.0.1 on both ends of the Electron ⇄ .NET socket bridge made it start visibly faster.
I don't have a confirmed root cause. My guess is that on those machines localhost goes through name resolution (and/or resolves to ::1 first, where nothing is listening), so each connection attempt costs a delay before falling back to IPv4.
Where the two ends disagree today
- src/ElectronNET.Host/main.js, in startSocketApiBridge (~line 264) — the bind address depends on whether the port was forced:
const host = !port ? '127.0.0.1' : 'localhost';
- src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs, in the constructor — the client always uses the name:
this.socketUrl = $"http://localhost:{this.socketPort}";
Steps to Reproduce:
- On Windows 11, create (or take) any Electron.NET app targeting win-x64.
- Run electronize start and time from launch to the first interactive window.
- Edit main.js to const host = '127.0.0.1'; (unconditionally) and SocketBridgeService.cs to this.socketUrl = $"http://127.0.0.1:{this.socketPort}";.
- Rebuild, run electronize start again, and compare the timing.
The difference was clear on the affected machines.
I don't know the consequences of hard-coding the literal — whether any supported scenario relies on localhost resolving to something other than 127.0.0.1, or on the host binding ::1. The conditional in main.js presumably exists for a reason I'm not aware of. Happy to open a PR if the approach seems acceptable.
Possibly related to #1024.
On some of our Windows machines, app startup was noticeably slow. Replacing localhost with 127.0.0.1 on both ends of the Electron ⇄ .NET socket bridge made it start visibly faster.
I don't have a confirmed root cause. My guess is that on those machines localhost goes through name resolution (and/or resolves to ::1 first, where nothing is listening), so each connection attempt costs a delay before falling back to IPv4.
Where the two ends disagree today
const host = !port ? '127.0.0.1' : 'localhost';
this.socketUrl = $"http://localhost:{this.socketPort}";
Steps to Reproduce:
The difference was clear on the affected machines.
I don't know the consequences of hard-coding the literal — whether any supported scenario relies on localhost resolving to something other than 127.0.0.1, or on the host binding ::1. The conditional in main.js presumably exists for a reason I'm not aware of. Happy to open a PR if the approach seems acceptable.
Possibly related to #1024.