I'm trying to add reconnection behaviour to capabilities with autoReconnect, but the behaviour isn't what I'd expect when I have multiple levels of reconnecting capabilities that are pipelined:
This example code deliberately creates capability B as disconnected, so I'd expect an attempt to reconnect the B capability, but instead, only reconnection of the A capability is attempted:
reconnect-test.cpp:
#include "reconnect-test.capnp.h"
#include <capnp/reconnect.h>
#include <kj/main.h>
#include <kj/async.h>
#include <kj/debug.h>
int main(int argc, char* argv[]) {
kj::EventLoop loop;
kj::WaitScope waitScope{loop};
auto b = capnp::autoReconnect([&](){
KJ_LOG(WARNING, "Reconnecting B");
return TestB::Client{KJ_EXCEPTION(DISCONNECTED)};
});
auto a = capnp::autoReconnect([&]{
KJ_LOG(WARNING, "Reconnecting A");
return b.getARequest().send().getA();
});
try {
a.typelessRequest(0, 0, nullptr).send().wait(waitScope);
}
catch (kj::Exception& exc) {
KJ_LOG(ERROR, "1", exc);
}
try {
a.typelessRequest(0, 0, nullptr).send().wait(waitScope);
}
catch (kj::Exception& exc) {
KJ_LOG(ERROR, "2", exc);
}
}
Output:
reconnect-test.cpp:12: warning: Reconnecting B
reconnect-test.cpp:17: warning: Reconnecting A
reconnect-test.cpp:17: warning: Reconnecting A
reconnect-test.cpp:25: error: 1; exc = reconnect-test.cpp:13: disconnected
reconnect-test.cpp:17: warning: Reconnecting A
reconnect-test.cpp:32: error: 2; exc = reconnect-test.cpp:13: disconnected
I'd expect the second attempt to result in a reconnection of the broken capability B when the (eventual) call to getARequest() occurs?
If I remove the pipelining, and force the call to getARequest to complete, then B reconnects just fine.
Vaci