Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileDescriptorEvent blocks I/O #1583

Closed
japplegame opened this issue Oct 3, 2016 · 4 comments
Closed

FileDescriptorEvent blocks I/O #1583

japplegame opened this issue Oct 3, 2016 · 4 comments

Comments

@japplegame
Copy link
Contributor

japplegame commented Oct 3, 2016

Looks like FileDescriptorEvent blocks other vibe.d I/O
This code

/+ dub.json:
    {
        "name": "test",
        "dependencies": {
            "vibe-d:core": "0.7.29"
        }
    }
+/

import std.stdio;
import std.socket;
import std.datetime;
import vibe.core.core;

void main() {
    runTask({
        writeln("start task");
        auto pair = socketPair();
        auto evt = createFileDescriptorEvent(pair[1].handle, FileDescriptorEvent.Trigger.any);
        //destroy(evt);
        writeFile("dummy.txt", cast(immutable ubyte[]) "1234567890");
        writeln("end task");
        exitEventLoop();
    });
    runEventLoop();
}

prints

start task

end never exits the event loop.
Looks like task hangs on writeFile().
If to uncomment destroy(evt) then code works as expected.

@s-ludwig
Copy link
Member

s-ludwig commented Oct 4, 2016

@japplegame
Copy link
Contributor Author

Turning sockets to a non-blocking mode doesn't help.

...
pair[0].blocking = false;
pair[1].blocking = false;
auto evt = createFileDescriptorEvent(pair[1].handle, FileDescriptorEvent.Trigger.any);
...

@s-ludwig
Copy link
Member

s-ludwig commented Oct 5, 2016

Okay, I'll try to reproduce this tomorrow.

@s-ludwig
Copy link
Member

s-ludwig commented Oct 6, 2016

The problem turned out to be that libevent looped infinitely in a call to event_base_loop(m_eventLoop, EVLOOP_NONBLOCK);, because the file descriptor is in write-ready state, so that every loop iteration fires an event. I'll add EVLOOP_ONCE to avoid that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants