apple / swift-distributed-actors

Peer-to-peer cluster implementation for Swift Distributed Actors
https://apple.github.io/swift-distributed-actors/
Apache License 2.0
584 stars 54 forks source link

Fix DA/ClusterSystem retain cycles - system actors cannot be strong retained; release them on shutdown #568

Open ktoso opened 4 years ago

ktoso commented 4 years ago

We weakened the actors holding it only via a weak yet should investigate more what could hold it more than necessary.

See https://github.com/apple/swift-distributed-actors/pull/565 and https://github.com/apple/swift-distributed-actors/pull/322

ktoso commented 2 years ago

Implemented an actor leak detector:


Test Case '-[DistributedActorsTests.ClusterDiscoveryTests test_discovery_shouldInitiateJoinsToNewlyDiscoveredNodes]' started.
DistributedActorsTestKit/ClusterSystemXCTestCase.swift:60: Fatal error: !!!!!! DETECTED LEAKED ACTORS: 3 !!!!
BEFORE ============================================
NOW ===============================================
DistributedActors.OpLogDistributedReceptionist
  - count: 1
  - ids: ["0x11f70f380"]
DistributedActors.ClusterEventStreamActor
  - count: 1
  - ids: ["0x1281089e0"]
DistributedActors.ClusterControl.(MembershipHolder in _1E7381868A8BFB9E946FBA4168BEE1E3)
  - count: 1
  - ids: ["0x600003cc0180"]
DIFF ==============================================
DistributedActors.OpLogDistributedReceptionist
  - count: 1
  - ids: ["0x11f70f380"]
DistributedActors.ClusterEventStreamActor
  - count: 1
  - ids: ["0x1281089e0"]
DistributedActors.ClusterControl.(MembershipHolder in _1E7381868A8BFB9E946FBA4168BEE1E3)
  - count: 1
  - ids: ["0x600003cc0180"]
DIFF ==============================================
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

`// TODO: Enable and fix leaks; today we have reference cycles between system actors and the system that don't get broken

ktoso commented 2 years ago

See InspectKit https://github.com/apple/swift-distributed-actors/pull/1055/commits/9cc0673606a0bab34cf121186fb790b669ba14d9