Skip to content

Requests to actors that quit fail with unexpected error code #2070

@dominiklohmann

Description

@dominiklohmann

We noticed that we had a self->mail(…).request(…).then(…) chain where the error response handler was called with a default-constructed error.

It turns out that this happens when the receiver calls quit(err)—all requests to that actor will then receive err instead of the expected sec::request_receiver_down.

/// Indicates that the receiver of a request is no longer alive.
request_receiver_down,

I am pretty sure this used to work, although I haven't verified it. We started seeing this issue after updating our CAF version to the current master branch.

The following unit test fails as a reliable and minimal reproduction:

diff --git a/libcaf_core/caf/mixin/requester.test.cpp b/libcaf_core/caf/mixin/requester.test.cpp
index 1eed7a384..4206f612a 100644
--- a/libcaf_core/caf/mixin/requester.test.cpp
+++ b/libcaf_core/caf/mixin/requester.test.cpp
@@ -379,6 +379,28 @@ TEST("GH-698 regression") {
   check_eq(client->strong_refs, 1u);
 }
 
+TEST("request_receiver_down regression") {
+  auto server = sys.spawn([this](event_based_actor* self) {
+    self->quit();
+    return behavior{
+      [](int32_t x) -> caf::result<int32_t> {
+        return x;
+      },
+    };
+  });
+  auto client = sys.spawn([this, server](event_based_actor* self) {
+    self->request(server, infinite, 0).then([](int32_t) {
+      test::runnable::current().fail("unexpected");
+    },
+    [this](const error& err) {
+      // This error handler gets called with whatever `quit` is being called
+      // with instead of the desired `sec::request_receiver_down`.
+      check_eq(err, sec::request_receiver_down);
+    });
+  });
+  dispatch_messages();
+}
+
 } // WITH_FIXTURE(fixture)
 
 } // namespace

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions