Skip to content

Wait for the subscription confirmation (pubsub.Receive) before returning the watch. - #379

Closed
Haven Xia (HavenXia) wants to merge 1 commit into
agent-substrate:mainfrom
HavenXia:fix-watchworkers-subscribe-race
Closed

Haven Xia (HavenXia) wants to merge 1 commit into
agent-substrate:mainfrom
HavenXia:fix-watchworkers-subscribe-race

Conversation

@HavenXia

@HavenXia Haven Xia (HavenXia) commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

Attempt to fix the flaky run-tests

Hit this during tests

2026/07/07 21:55:05 INFO Handle RPC method=/ateapi.Control/ListWorkers req="" resp="workers:{worker_namespace:\"ns-list-workers-1783461303995756942\"  worker_pool:\"pool1\"  worker_pod:\"worker-1\"  ip:\"127.0.0.1\"  version:1  worker_pod_uid:\"5b2e6977-365a-4566-94dd-72d5e17e6de7\"  node_name:\"node1\"}  workers:{worker_namespace:\"ns-multi-pool-1783461304982213577\" .....

2026/07/07 21:55:05 INFO Handle RPC method=/ateapi.Control/ResumeActor req="actor_ref:{atespace:\"test-atespace\"  name:\"id1\"}" resp=<nil> err="workflow failed at step AssignWorker: rpc error: code = FailedPrecondition desc = no free workers available" elapsed-time=465.688µs
    functional_test.go:1495: ResumeActor failed: rpc error: code = FailedPrecondition desc = no free workers available
--- FAIL: TestSuspendActor (0.16s)

The test failed at 1st run but succeed in the 2nd attempt without any change.
image

ListWorker finds workers but WatchWorkers failed since it use the workerCache code path to check existence. So making sure we receive the pub/sub message should fix it.

It's a good idea to open an issue first for discussion.

  • Tests pass
  • Appropriate changes to documentation are included in the PR

@HavenXia
Haven Xia (HavenXia) force-pushed the fix-watchworkers-subscribe-race branch from 916b447 to 773fc34 Compare July 7, 2026 23:32
@HavenXia
Haven Xia (HavenXia) marked this pull request as ready for review July 7, 2026 23:36
@HavenXia Haven Xia (HavenXia) changed the title ateredis: Wait for the subscription confirmation (pubsub.Receive) before returning the watch. Wait for the subscription confirmation (pubsub.Receive) before returning the watch. Jul 7, 2026
@HavenXia Haven Xia (HavenXia) added the kind/bug Something isn't working / bugfixes label Jul 8, 2026
pubsub := s.rdb.Subscribe(watchCtx, workerPubSubChannel)
// Wait for the server to confirm the subscription; otherwise events published
// right after we return can race the SUBSCRIBE and be lost for good.
if _, err := pubsub.Receive(watchCtx); err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this guaranteed to be non-blocking?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's non-blocking, should we wrap it with a timeout?
Also I noticed this change has already been merged to main in #353 that did the exact same thing.

@HavenXia

Copy link
Copy Markdown
Member Author

Close as a duplicate of #353

Zoe Zhao (zoez7) pushed a commit that referenced this pull request Jul 8, 2026
Should have a timeout to make the fix in #353 non-blocking.
Originated from #379

- [x] Tests pass
- [x] Appropriate changes to documentation are included in the PR
@HavenXia
Haven Xia (HavenXia) deleted the fix-watchworkers-subscribe-race branch July 9, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working / bugfixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants