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

Comments

Projects
None yet
2 participants
@japplegame
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

This comment has been minimized.

Show comment
Hide comment
@japplegame

This comment has been minimized.

Show comment
Hide comment
@japplegame

japplegame Oct 4, 2016

Contributor

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);
...
Contributor

japplegame commented Oct 4, 2016

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

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Oct 5, 2016

Member

Okay, I'll try to reproduce this tomorrow.

Member

s-ludwig commented Oct 5, 2016

Okay, I'll try to reproduce this tomorrow.

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Oct 6, 2016

Member

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.

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.

@s-ludwig s-ludwig closed this in a03d791 Oct 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment