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

Closed
ibuclaw opened this Issue Jul 31, 2014 · 1 comment

Comments

Projects
None yet
1 participant
@ibuclaw

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);
        st_threadsSignal.emit();
        while (st_threads.length)
                st_threadShutdownCondition.wait();  <--- here
}

Considering the following:

import vibe.d;

import core.thread;
import core.time;

void sleep()
{
  while(true)
    Thread.sleep(5.seconds);
}

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

    static Thread sleeper = null;
    if (sleeper is null)
    {
        sleeper = new Thread(&sleep);
        sleeper.isDaemon(true);
        sleeper.start();
    }
}

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 127.0.0.1:8080
^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.

@ibuclaw

This comment has been minimized.

Show comment
Hide comment
@ibuclaw

ibuclaw commented Sep 15, 2014

Thanks!

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