RejectedSoftware Forums

Sign up

After closing the application it runs in the background

I try a simple application.

import vibe.d;

void kök(HTTPServerRequest istek, HTTPServerResponse yanıt)
{
    yanıt.writeBody("Merhaba, Dünya!");
}

void main()
{
	auto ayarlar = new HTTPServerSettings;
    ayarlar.port = 8080;
    ayarlar.bindAddresses = ["::1", "127.0.0.1"];
	listenHTTP(ayarlar, &kök);

	logInfo("Lütfen tarayıcınızda http://127.0.0.1:8080/ adresini açınız.");
	runApplication();
}

It works as expected for the first time. But when I close the application using Ctrl-D or Ctrl-Z key combination I get an error like this.

Running ./ilk 
Failed to listen on ::1:8080
Failed to listen on 127.0.0.1:8080
object.Exception@/home/erdem/.dub/packages/vibe-d-0.8.6/vibe-d/http/vibe/http/server.d(2090): Failed to listen for incoming HTTP connections on any of the supplied interfaces.
----------------
/usr/include/dmd/phobos/std/exception.d:515 pure @safe void std.exception.bailOut!(Exception).bailOut(immutable(char)[], ulong, scope const(char)[]) [0x55d927401182]
/usr/include/dmd/phobos/std/exception.d:436 pure @safe bool std.exception.enforce!().enforce!(bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x55d92741cd2e]
/home/erdem/.dub/packages/vibe-d-0.8.6/vibe-d/http/vibe/http/server.d:2090 @safe vibe.http.server.HTTPListener vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings, void delegate(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) @safe) [0x55d9274a4c30]
/home/erdem/.dub/packages/vibe-d-0.8.6/vibe-d/http/vibe/http/server.d:103 @safe vibe.http.server.HTTPListener vibe.http.server.listenHTTP!(vibe.http.server.HTTPServerSettings).listenHTTP(vibe.http.server.HTTPServerSettings, void delegate(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse) @safe) [0x55d9274019e9]
/home/erdem/.dub/packages/vibe-d-0.8.6/vibe-d/http/vibe/http/server.d:147 vibe.http.server.HTTPListener vibe.http.server.listenHTTP!(vibe.http.server.HTTPServerSettings).listenHTTP(vibe.http.server.HTTPServerSettings, void function(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)*) [0x55d92740190a]
source/app.d:15 _Dmain [0x55d927400e6c]
Program exited with code 1

If I change the port number (let's say 8081) and run it a second time it works as expected.

Netstat output is as follows :

$ sudo netstat -nlp | grep 8080
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               DİNLE      3240/./ilk          
tcp6       0      0 ::1:8080                :::*                    DİNLE      3240/./ilk    

The name of the program is "ilk".

Re: After closing the application it runs in the background

On 11/24/19 4:31 PM, Erdem wrote:

I try a simple application.

import vibe.d;

void kök(HTTPServerRequest istek, HTTPServerResponse yanıt)
{
     yanıt.writeBody("Merhaba, Dünya!");
}

void main()
{
	auto ayarlar = new HTTPServerSettings;
     ayarlar.port = 8080;
     ayarlar.bindAddresses = ["::1", "127.0.0.1"];
	listenHTTP(ayarlar, &kök);

	logInfo("Lütfen tarayıcınızda http://127.0.0.1:8080/ adresini açınız.");
	runApplication();
}

It works as expected for the first time. But when I close the application using Ctrl-D or Ctrl-Z key combination I get an error like this.

You can have the OS hold open connections, but they will be in TIMEWAIT
mode or something like that. Though it appears that you aren't actually
exiting the program? Ctrl-Z backgrounds the program, that won't kill it.
Ctrl-D doesn't kill the application, but exits your shell.

-Steve

Re: After closing the application it runs in the background

On Mon, 25 Nov 2019 10:47:47 -0500, Steven Schveighoffer wrote:

Though it appears that you aren't actually
exiting the program? Ctrl-Z backgrounds the program, that won't kill it.
Ctrl-D doesn't kill the application, but exits your shell.

I run dub again to create a new project.

$ dub init hello --type=vibe.d
$ cd hello
$ dub

It works fine for the first time. When I execute it for the second time using dub, I get the same error message that I mentioned above.

$ ps aux | grep hello
erdem 2688 0.0 0.2 306464 11464 pts/0 Tl 22:58 0:00 ./hello

I tried to kill application from the command line.

$ kill 2688
$ sudo kill 2688

When I check it still runs in the background.

The only change I made from normal installation was to change linker as suggested here.

vibe.d faster linking

Re: After closing the application it runs in the background

On Mon, 25 Nov 2019 20:33:09 GMT, Erdem wrote:

I tried to kill application from the command line.

$ kill 2688
$ sudo kill 2688

I should be able to kill application using this command.

$ sudo kill -9 {PID}

The real problem was that I was using Ctrl-Z instead of Ctrl-C to terminate a vibe.d application.

Re: After closing the application it runs in the background

On 11/25/19 3:43 PM, Erdem wrote:

On Mon, 25 Nov 2019 20:33:09 GMT, Erdem wrote:

I tried to kill application from the command line.

$ kill 2688
$ sudo kill 2688

I should be able to kill application using this command.

$ sudo kill -9 {PID}

Kill -9 does not give the application any chance to clean up. In this
case it's very possible the socket binding will be in TIMEWAIT. You will
have to wait for the timeout.

It's much better if you kill without the -9 (equivalent to kill -15) ,
or use ctrl-c (equivalent to kill -2), as this tells the vibe subsystem
to shutdown gracefully.

-Steve