network audit fixes#47
Merged
Merged
Conversation
… races
- downloads: wedge-forever paths (inbound-F catch, missing stall
timeout), watchdog token collisions, duplicate queueing, retry
classifier misclassifying our own teardown errors
- cancellation: cancelDownload/cancelUpload APIs wired from the UI;
streaming loops check per chunk, completion can't stomp .cancelled
- peer connections: double-resume crash on bind retry (generation-
stamped attempts), out-of-order file bytes after stopReceiving,
event-stream/Task leak per failed dial, per-IP slot accounting,
pool key collisions, obfuscated->raw handoff residue
- coordination: distributed parent death detection, pending-browse
leaks, login timeout races, NAT external-port re-advertisement
- protocol: decompression truncation, compress buffer headroom,
zero-byte files, deleted broken fileSearchRoom (code 25)
- uploads: duplicate QueueUpload dedup, PF short-read guard, slot
double-count, speed limit setting wired, legacy direction=download
TransferRequests answered, atomic share rescan
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.
Description
This PR introduces several improvements and fixes to the peer-to-peer connection and file transfer logic, focusing on race condition prevention, robust timeout handling, and more reliable data buffering. The changes ensure that connection attempts are properly tracked, timeouts reliably cancel pending operations, and file transfer buffers are used consistently to avoid data loss or duplication.
Connection attempt tracking and race condition prevention:
connectAttemptGeneration) to uniquely identify each connection attempt, ensuring that only the latest attempt can update state or resume continuations, preventing race conditions when multiple attempts overlap. (PeerConnection.swift) [1] [2] [3] [4] [5] [6]Timeout and cancellation handling:
NWConnection, preventing orphaned continuations and guaranteeing that timeouts are honored. (PeerConnection.swift,FileConnectionAttempt.swift) [1] [2] [3]claimResumeclosure and a mutex-protected timeout task, ensuring only one outcome is processed and resources are cleaned up correctly. (FileConnectionAttempt.swift)File transfer buffer and receive logic:
PeerConnection.swift) [1] [2] [3]PeerConnection.swift)Thread safety and state tracking:
lastActivityAtto be mutex-protected and accessible from nonisolated contexts, improving thread safety for activity tracking. (PeerConnection.swift)Robustness and cleanup:
PeerConnection.swift,FileConnectionAttempt.swift) [1] [2]These changes collectively make connection management and file transfers more robust, race-free, and reliable under concurrent and error conditions.
How to test
Author checklist
This PR: