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

Server with daemon threads never shuts down. #758

ibuclaw opened this Issue Jul 31, 2014 · 1 comment


None yet
1 participant

ibuclaw commented Jul 31, 2014

I believe the area where this bug manifests itself is in vibe.core.core in static ~this()

// if we are the main thread, wait for all others before terminating
is_main_thread = idx == 0;
if (is_main_thread) { // we are the main thread, wait for others
        atomicStore(st_term, true);
        while (st_threads.length)
                st_threadShutdownCondition.wait();  <--- here

Considering the following:

import vibe.d;

import core.thread;
import core.time;

void sleep()

shared static this()
    auto settings = new HTTPServerSettings;
    settings.port = 8080;
    settings.bindAddresses = ["::1", ""];
    listenHTTP(settings, &hello);

    static Thread sleeper = null;
    if (sleeper is null)
        sleeper = new Thread(&sleep);

void hello(HTTPServerRequest req, HTTPServerResponse res)
    res.writeBody("Hello, World!");

When you send a kill signal to the running server, it never actually shuts down.

# ./testsite 
Listening for HTTP requests on ::1:8080
Listening for HTTP requests on
^CReceived signal 2. Shutting down.
^CReceived signal 2. Shutting down.
^CReceived signal 2. Shutting down.
^CReceived signal 2. Shutting down.
^CReceived signal 2. Shutting down.

It instead waits forever for threads that never terminate to end.


This comment has been minimized.

Show comment
Hide comment

ibuclaw commented Sep 15, 2014


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