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

connectTCP could crash if it was interrupted (libevent driver) #1331

Closed
japplegame opened this issue Nov 11, 2015 · 5 comments
Closed

connectTCP could crash if it was interrupted (libevent driver) #1331

japplegame opened this issue Nov 11, 2015 · 5 comments

Comments

@japplegame
Copy link
Contributor

Assertion point - https://github.com/rejectedsoftware/vibe.d/blob/v0.7.26/source/vibe/core/drivers/libevent2_tcp.d#L648

Looks like it happens when connection is actually established but right before dispatching onSocketEvent the vibe.d core interrupts the task, throws InterruptException, which is caught here - https://github.com/rejectedsoftware/vibe.d/blob/v0.7.26/source/vibe/core/drivers/libevent2.d#L311. TCPContext is destroyed and after that onSocketEvent called by libevent with wrong context.

Such a situation seems very unlikely, but in the real world we are confronted with it every few days.
We use something similar to this code:

auto current = Task.getThis;
auto timer = setTimer(timeout, &current.interrupt);
try {
    scope(exit) timer.stop();
    requestHTTP(...);
} catch(InterruptException exception) {
    throw new Exception("task timed out");
}
@japplegame
Copy link
Contributor Author

Can anyone help me?
These crashes occur more often as load growth.

@s-ludwig
Copy link
Member

I've added a fix on master, can you verify if it works for you?

@japplegame
Copy link
Contributor Author

Thank you. I'll try it.

@japplegame
Copy link
Contributor Author

Interrupted connection crash was fixed, but another crash introduced (most likely by commit 9b7b3f6).
Trying to connect with a non-listening address causes a crash:

Task terminated with uncaught exception: Failed to connect to 127.0.0.1:8080: Error reading from socket 9 (Connection refused)                                                                
[err] bufferevent.c:611: Assertion bufev_private->refcnt > 0 failed in _bufferevent_decref_and_unlock

Code

import vibe.d;

shared static this() {
    runTask({
        requestHTTP("http://127.0.0.1:8080",
            (scope HTTPClientRequest req) {},
            (scope HTTPClientResponse res) {}
        );
    });
}

Double bufferevent_free?

@japplegame
Copy link
Contributor Author

Ping

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