apple / swift-distributed-actors

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

WorkingPool unexpected behaviour when workers are on different node #1134

Open akbashev opened 12 months ago

akbashev commented 12 months ago

Description WorkingPool unexpected behaviour when workers are on different node

Steps to reproduce https://github.com/akbashev/WorkerPoolTest

Two nodes:

  1. Join nodes and wait to be up.
  2. Spawn master with working pool on Master node.
  3. Spawn workers on Worker node.

If you run an example and submit some work—WorkingPool will terminate all workers in selectWorker() function, seems like actor is none here:

if let worker = self.workers[selectedWorkerID]?.actor {

Expected behavior Pool is routing job to workers, e.g. will log:

2023-07-20T07:36:38+0200 info worker : cluster/node=sact://worker@127.0.0.1:1111 [WorkingPoolTest] Done check for /user/Worker-d

Environment MacOS 14.0 Beta (23A5286i), Xcode 15.0 Beta 4 (15A5195m), Swift 5.9

ktoso commented 12 months ago

Thanks for reporting, will look soon

akbashev commented 11 months ago

btw think I've pushed a error in SPM in example before 🙈 fixed that, now should work

akbashev commented 10 months ago

Ok, after a bit of testing and checking repo around, think this PR and particular WeakWhenLocal wrapper can fix this issue. Will double check.

Probably there should be a better way to fix :)

akbashev commented 8 months ago

Actually looking back again into issue and thinking a bit more about, introduction of some type like WeakWhenLocal makes sense.

Making worker reference either just weak or just strong will both give you a problem:

So you (or system) need to know if it's local or remote reference for WorkerPool. And this PR is actually should fix it. 🤔