It also hangs on Linux and Mac.
However, we have also noticed that when the broker receives a datagram during execution, it does not encounter this error. The following example illustrates.
#include <iostream>
#include <chrono>
#include <thread>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#include "caf/config.hpp"
using namespace caf;
using namespace caf::io;
namespace {
behavior server(broker* self, uint16_t port) {
auto epair = self->add_udp_datagram_servant(port);
self->set_exit_handler([=](exit_msg& msg) {
aout(self) << "Received exit" << std::endl;
aout(self) << "Closed: " << self->close(epair.value().first) << std::endl;
self->quit(msg.reason);
});
return {
[=](const new_datagram_msg& msg) {
aout(self) << "Received msg: " << std::string(msg.buf.data(), msg.buf.size()) << std::endl;
}
};
}
}
int main() {
actor_system_config cfg;
cfg.load<middleman>();
actor_system system(cfg);
auto serverActor = system.middleman().spawn_broker(server, 9952);
std::this_thread::sleep_for(std::chrono::seconds(10));
anon_send_exit(serverActor, exit_reason::user_shutdown);
return 0;
}
If the broker receives a datagram before exit is sent, then the program ends normally. However, if it does not, then it hangs in the destruction of the actor_system. Interestingly, the self->close() returns false either way. When the program hangs netstat still shows the UDP port active.
$ netstat -an | grep 9952
udp46 0 0 *.9952 *.*