I'm seeing some weird behaviour with FileDescriptorEvents. Consider this reduced example for vibed 0.7.20:
module main;
import core.sys.posix.sys.socket, core.sys.posix.fcntl;
import std.datetime, std.stdio;
import vibe.d;
void main()
{
auto c = new C();
runTask(&c.test);
setIdleHandler(&c.idle);
runEventLoop();
}
class C
{
bool idle()
{
static SysTime time;
writeln(Clock.currTime - time);
time = Clock.currTime;
return false;
}
void test()
{
auto address = resolveHost("google.com", AF_INET, true);
address.port = 80;
auto fd = socket(address.family, SOCK_STREAM, 0);
auto flags = fcntl(fd, F_GETFL, 0);
flags = flags | O_NONBLOCK;
assert(fcntl(fd, F_SETFL, flags) == 0);
connect(fd, address.sockAddr, address.sockAddrLen);
auto _watcher = createFileDescriptorEvent(fd,FileDescriptorEvent.Trigger.any);
_watcher.wait(dur!"seconds"(30));
}
}
When I run this the idle handler is called with very small delays (~3 μs) for some time and the OS task manager shows 100% CPU consumption. If I use FileDescriptorEvent for real I/O operations I see 100% CPU load all the time.
With this simple example the CPU load normalizes after a few seconds but with more complicated examples I also managed to keep the CPU busy even after all tasks have finished. I can't seem to reproduce that now though.
OS is linux x86_64, compilers dmd 2065 or gdc 2064, libevent backend, vibed 0.7.20.
Is there anything wrong with the way I'm using FileDescriptorEvent or is this some kind of bug?