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

Comments

Projects
None yet
2 participants
@japplegame
Contributor

japplegame commented Nov 11, 2015

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

This comment has been minimized.

Show comment
Hide comment
@japplegame

japplegame Nov 12, 2015

Contributor

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

Contributor

japplegame commented Nov 12, 2015

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

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Nov 12, 2015

Member

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

Member

s-ludwig commented Nov 12, 2015

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

@japplegame

This comment has been minimized.

Show comment
Hide comment
@japplegame

japplegame Nov 12, 2015

Contributor

Thank you. I'll try it.

Contributor

japplegame commented Nov 12, 2015

Thank you. I'll try it.

@japplegame

This comment has been minimized.

Show comment
Hide comment
@japplegame

japplegame Nov 15, 2015

Contributor

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?

Contributor

japplegame commented Nov 15, 2015

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

This comment has been minimized.

Show comment
Hide comment
@japplegame

japplegame Nov 27, 2015

Contributor

Ping

Contributor

japplegame commented Nov 27, 2015

Ping

@japplegame japplegame closed this Nov 8, 2017

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