🐛 Fix Bonjour service registering with port 0 due to race with server startup#3772
Merged
guiyanakuang merged 3 commits intomainfrom Feb 8, 2026
Merged
🐛 Fix Bonjour service registering with port 0 due to race with server startup#3772guiyanakuang merged 3 commits intomainfrom
guiyanakuang merged 3 commits intomainfrom
Conversation
… startup
DesktopPasteBonjourService's init block launches coroutines that
immediately collect networkInterfaces and call setup(), which can
execute before DesktopPasteServer.start() has set the actual port.
This causes the Bonjour service to advertise port 0.
Fix: Expose server port as StateFlow<Int> in PasteServer (backed by
MutableStateFlow). DesktopPasteBonjourService.setup() now awaits
portFlow.first { it > 0 } before proceeding with registration,
ensuring the correct port is always used regardless of init ordering.
Closes #3771
Co-Authored-By: Claude <noreply@anthropic.com>
Move portFlow.first { it > 0 } from DesktopPasteBonjourService into
EndpointInfoFactory.createEndpointInfo(), so every caller (Bonjour,
SyncRouting, SyncResolver, QRCodeGenerator) is protected against
reading port before server start.
- EndpointInfoFactory.createEndpointInfo → suspend, awaits portFlow
- SyncInfoFactory.createSyncInfo → suspend (propagated)
- QRCodeGenerator.buildQRCode/generateQRCode → suspend (propagated)
- Revert pasteServer injection from DesktopPasteBonjourService
- Update SyncTest to call createEndpointInfo inside runBlocking
Co-Authored-By: Claude <noreply@anthropic.com>
When jmDNS fires serviceResolved/serviceRemoved events with empty textBytes, skip decoding instead of letting it fail with JsonDecodingException. This avoids unnecessary exception overhead for a normal jmDNS behavior during partial discovery. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StateFlow<Int>and makeEndpointInfoFactory.createEndpointInfo()suspend to await a valid port (> 0), fixing a race condition whereDesktopPasteBonjourServicecould register with port 0 before the server finished startingsuspendtoSyncInfoFactory.createSyncInfo(),QRCodeGenerator.buildQRCode(), andgenerateQRCode()DesktopServiceListener.serviceResolved/serviceRemovedwhentextBytesis empty, avoiding unnecessaryJsonDecodingExceptionduring partial jmDNS discoveryFixes #3771
Test plan
createEndpointInfo)SyncTest.testTrustAndHeartbeat)🤖 Generated with Claude Code