RejectedSoftware Forums

Sign up

Why does the following code not terminate?

module app;

import vibe.core.core;
import core.thread;

int main()
{
    auto udp = listenUDP(0);
    udp.connect("127.0.0.1", 31722);
    udp.send(cast(ubyte[])"Test");
    return runEventLoop();
}

Code just continually runs, does not terminate despite connecting and sending if it can.

Re: Why does the following code not terminate?

On Mon, 03 Feb 2014 15:13:41 GMT, Kelet wrote:

module app;

import vibe.core.core;
import core.thread;

int main()
{
    auto udp = listenUDP(0);
    udp.connect("127.0.0.1", 31722);
    udp.send(cast(ubyte[])"Test");
    return runEventLoop();
}

Code just continually runs, does not terminate despite connecting and sending if it can.

Dicebot told me that this is just the expected behavior. However, without the runEventLoop(), it does not terminate on Linux but it does on Windows. This is likely due to the different drivers being used. Ultimately, I'd just like it to terminate after it sends the packet while using a custom main.

Re: Why does the following code not terminate?

Am 03.02.2014 16:54, schrieb Kelet:

On Mon, 03 Feb 2014 15:13:41 GMT, Kelet wrote:

module app;

import vibe.core.core;
import core.thread;

int main()
{
     auto udp = listenUDP(0);
     udp.connect("127.0.0.1", 31722);
     udp.send(cast(ubyte[])"Test");
     return runEventLoop();
}

Code just continually runs, does not terminate despite connecting and sending if it can.

Dicebot told me that this is just the expected behavior. However, without the runEventLoop(), it does not terminate on Linux but it does on Windows. This is likely due to the different drivers being used. Ultimately, I'd just like it to terminate after it sends the packet while using a custom main.

The root cause is
#212. I'll look
into why it doesn't terminate even without the runEventloop().

Re: Why does the following code not terminate?

Am 04.02.2014 10:44, schrieb Sönke Ludwig:

Am 03.02.2014 16:54, schrieb Kelet:

On Mon, 03 Feb 2014 15:13:41 GMT, Kelet wrote:

module app;

import vibe.core.core;
import core.thread;

int main()
{
     auto udp = listenUDP(0);
     udp.connect("127.0.0.1", 31722);
     udp.send(cast(ubyte[])"Test");
     return runEventLoop();
}

Code just continually runs, does not terminate despite connecting and
sending if it can.

Dicebot told me that this is just the expected behavior. However,
without the runEventLoop(), it does not terminate on Linux but it
does on Windows. This is likely due to the different drivers being
used. Ultimately, I'd just like it to terminate after it sends the
packet while using a custom main.

The root cause is
#212. I'll look
into why it doesn't terminate even without the runEventloop().

This terminates fine for me on either Windows or Linux:

import vibe.core.net;

void main()
{
	auto udp = listenUDP(0);
	udp.connect("127.0.0.1", 31722);
	udp.send(cast(ubyte[])"Test");
}

Do you have anything in addition to this?

Re: Why does the following code not terminate?

On Tue, 04 Feb 2014 11:04:32 +0100, Sönke Ludwig wrote:

This terminates fine for me on either Windows or Linux:

import vibe.core.net;

void main()
{
	auto udp = listenUDP(0);
	udp.connect("127.0.0.1", 31722);
	udp.send(cast(ubyte[])"Test");
}

Do you have anything in addition to this?

Alright, it terminates for me now. Not sure if it was a change or just me messing up here. However, since the change, if I have runEventLoop() toward the end, it gives me an error about releasing a TCP connection that is not owned. First of all, it's obviously a UDP connection (probably a typo in the source). Secondly, I guess I don't really understand the event loop in a VibeCustomMain application. It is blocking, and I oftentimes have a 'main loop' in my main function. Should I put this loop in a task, start up all of my tasks, and then runEventLoop()?

Thanks for all the help!

Re: Why does the following code not terminate?

Am 05.02.2014 13:51, schrieb Kelet:

On Tue, 04 Feb 2014 11:04:32 +0100, Sönke Ludwig wrote:

This terminates fine for me on either Windows or Linux:

import vibe.core.net;

void main()
{
	auto udp = listenUDP(0);
	udp.connect("127.0.0.1", 31722);
	udp.send(cast(ubyte[])"Test");
}

Do you have anything in addition to this?

Alright, it terminates for me now. Not sure if it was a change or just me messing up here. However, since the change, if I have runEventLoop() toward the end, it gives me an error about releasing a TCP connection that is not owned. First of all, it's obviously a UDP connection (probably a typo in the source). Secondly, I guess I don't really understand the event loop in a VibeCustomMain application. It is blocking, and I oftentimes have a 'main loop' in my main function. Should I put this loop in a task, start up all of my tasks, and then runEventLoop()?

Thanks for all the help!

Can you post a stack trace of the "TCP" connection error? I think I got
that once yesterday, but didn't track it down. I think it was some
assertion that was triggered, which then bypassed releasing the connection.

Regarding the message loop, usually the vibe.d event loop is the
message loop. On windows, you can use the win32 driver instead of the
libevent one and it will also process window messages. Similarly, on
Linux, you can use vibe.core.core.createFileDescriptorEvent to listen
on the X display connection(s) for events.

If that doesn't work in a particular situation, there are basically two
generic options:

  1. Start each message loop in a separate thread
  2. Embed one message loop into the other using a polling mechanism (e.g.
    call processEvents() every X msecs)

Re: Why does the following code not terminate?

On Wed, 05 Feb 2014 17:37:33 +0100, Sönke Ludwig wrote:

Can you post a stack trace of the "TCP" connection error? I think I got
that once yesterday, but didn't track it down. I think it was some
assertion that was triggered, which then bypassed releasing the connection.

I think I may have misreported that error, as it's not coming from this source code. However, here is the full error:

core.exception.AssertError@../../.dub/packages/vibe-d-master/source/vibe/core/drivers/libevent2.d(897): Trying to release a TCP connection that is not owned.
----------------
./theatre(_d_assert_msg+0x18) [0x816e8e8]
./theatre(void vibe.core.drivers.libevent2.Libevent2UDPConnection.release()+0xb3) [0x8135db3]
./theatre(ubyte[] vibe.core.drivers.libevent2.Libevent2UDPConnection.recv(ubyte[], vibe.core.net.NetworkAddress*)+0x19a) [0x8136272]
./theatre(ubyte[] theatre.net.connection.recv(ubyte[], vibe.core.net.NetworkAddress*)+0x41) [0x812f271]
./theatre(_Dmain+0x26) [0x8121f46]
./theatre(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().void __lambda1()+0x10) [0x8174578]
./theatre(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x81744f0]
./theatre(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x27) [0x817453f]
./theatre(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x81744f0]
./theatre(_d_run_main+0x117) [0x8174487]
./theatre(main+0x14) [0x812f1ec]
/usr/lib/libc.so.6(__libc_start_main+0xf3) [0xb7256993]
----------------

It is coming from: https://github.com/Kelet/theatre/tree/master/source

Whenever it recvs, the error is generated. You can just send it a UDP packet using the source code on this thread. It could just be me doing something wrong though.

Re: Why does the following code not terminate?

On Tue, 04 Feb 2014 11:04:32 +0100, Sönke Ludwig wrote:

This terminates fine for me on either Windows or Linux:

import vibe.core.net;

void main()
{
	auto udp = listenUDP(0);
	udp.connect("127.0.0.1", 31722);
	udp.send(cast(ubyte[])"Test");
}

Do you have anything in addition to this?

Actually, this code does not terminate for me on Linux using revision 2e9bde0 (the latest one at the time of writing).

Re: Why does the following code not terminate?

Am 05.02.2014 19:11, schrieb Kelet:

On Wed, 05 Feb 2014 17:37:33 +0100, Sönke Ludwig wrote:

Can you post a stack trace of the "TCP" connection error? I think I got
that once yesterday, but didn't track it down. I think it was some
assertion that was triggered, which then bypassed releasing the connection.

I think I may have misreported that error, as it's not coming from this source code. However, here is the full error:

core.exception.AssertError@../../.dub/packages/vibe-d-master/source/vibe/core/drivers/libevent2.d(897): Trying to release a TCP connection that is not owned.
(...)
----------------

It is coming from: https://github.com/Kelet/theatre/tree/master/source

Whenever it recvs, the error is generated. You can just send it a UDP packet using the source code on this thread. It could just be me doing something wrong though.

OK, should be fixed now. The assertion was simply wrong when called from
outside of a task.

Re: Why does the following code not terminate?

Am 05.02.2014 19:49, schrieb Kelet:

On Tue, 04 Feb 2014 11:04:32 +0100, Sönke Ludwig wrote:

This terminates fine for me on either Windows or Linux:

import vibe.core.net;

void main()
{
	auto udp = listenUDP(0);
	udp.connect("127.0.0.1", 31722);
	udp.send(cast(ubyte[])"Test");
}

Do you have anything in addition to this?

Actually, this code does not terminate for me on Linux using revision 2e9bde0 (the latest one at the time of writing).

So did it terminate before and now it hangs again? Or did it terminate
on Windows, but hangs on Linux?

At least I've tested on Linux/32, Linux/64, Windows, DMD 2.064.2 and DMD
2.065-b2, but it doesn't hang for me anywhere.