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

ConnectionPool.lockConnection() hangs under certain conditions. #1590

Closed
japplegame opened this issue Oct 8, 2016 · 1 comment
Closed

ConnectionPool.lockConnection() hangs under certain conditions. #1590

japplegame opened this issue Oct 8, 2016 · 1 comment

Comments

@japplegame
Copy link
Contributor

When using ConnectionPool.lockConnection() in parallel in multiple tasks (single thread), under certain conditions it hangs.

On my CentOS 7 x86_64 + vibe.d 0.7.29 this code

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

import std.stdio;
import std.socket;
import std.datetime;
import std.functional;
import vibe.core.core;
import vibe.core.log;
import vibe.core.concurrency;
import vibe.core.connectionpool;

class Conn {}

void main() {
    runTask({
        // create pool with 2 max connections
        auto pool = new ConnectionPool!Conn({ return new Conn; }, 2);
        auto task = Task.getThis(); // main task
        void worker(int id) {
            {
                auto conn = pool.lockConnection(); // <-- worker(4) hangs here
                sleep(1.msecs); // <-- important, without sleep everything works fine
            }
            task.send(id); // send signal to the main task
        }
        // run 4 tasks (2 * pool max connections)
        runTask(&worker, 1);
        runTask(&worker, 2);
        runTask(&worker, 3);
        runTask(&worker, 4);

        // wait for first signal and run one more task
        writefln("recv  %s", receiveOnly!int);
        runTask(&worker, 5);

        // wait for other signals
        writefln("recv  %s", receiveOnly!int);
        writefln("recv  %s", receiveOnly!int);
        writefln("recv  %s", receiveOnly!int);
        writefln("recv  %s", receiveOnly!int);

        exitEventLoop();
    });
    runEventLoop();
}

outputs

recv  1
recv  2
recv  3
recv  5

and never exits the even loop.
Where is recv 4?

@s-ludwig
Copy link
Member

s-ludwig commented Oct 8, 2016

Appears to be already fixed by #1563. I'll add this as a regression test.

@s-ludwig s-ludwig closed this as completed Oct 8, 2016
s-ludwig added a commit that referenced this issue Oct 8, 2016
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