RejectedSoftware Forums

Sign up

Pages: 1 2

App crashed with segfault.

My app crashed after running a few minutes:
I got the call stack by gdb:

Program received signal SIGSEGV, Segmentation fault.
0x000000000077ca11 in 
vibe.core.drivers.libevent2_tcp.onSocketEvent (
    buf_event=0xcd43f8, status=17, arg=0xcd54e0)
    at 
../../../../root/.dub/packages/vibe-d-0.7.22/source/vibe/core/drivers/libevent2_tcp.d:651

Here is the code of libevent2_tcp.d:

if (ctx.writeOwner && ctx.writeOwner != ctx.readOwner && 
ctx.writeOwner.running) {
    logTrace("resuming corresponding task%s...", ex is null ? "" 
: " with exception");
    if (ctx.writeOwner.fiber.state == Fiber.State.EXEC)  ctx.exception = ex;
    else ctx.core.resumeTask(ctx.writeOwner, ex);   //LINE 651
}


I dont know what is happening, anybody help? Thanks in advance.

Re: App crashed with segfault.

Here is my main code:

class SockServer
{
	void listen()
	{
		listenTCP(9991, (conn){ handleConn(conn); });
	}

	void handleConn(TCPConnection client)
	{
		scope(exit) client.close();
		
		ubyte[] pack = NetUtil.readPacket(client);
		Cmd cmd = NetUtil.deserialObj!(Cmd)(pack);
		NetUtil.printObj(cmd);
		if(cmd.cmdId==Cmds.Connect)
		{
			handleConnect(client,cmd);
		}
	}

	void handleConnect(TCPConnection client,ref Cmd cmd)
	{
		auto remote = connectTCP(cmd.connect.ip,cast(ushort)cmd.connect.port);
		if(remote is null) return;
		scope(exit)remote.close();
		forward(client,remote);
	}
	
	static void forward(TCPConnection client,TCPConnection remote)
	{
		auto wtask = runTask({
				remote.write(client);
			});
		client.write(remote);
		// wait for the tasks to finish
		wtask.join();
	}
}


Re: App crashed with segfault.

I post the quest again with better format:

Program received signal SIGSEGV, Segmentation fault.
0x000000000077ca11 in vibe.core.drivers.libevent2_tcp.onSocketEvent (
    buf_event=0xcd43f8, status=17, arg=0xcd54e0)
    at ../../../../root/.dub/packages/vibe-d-0.7.22/source/vibe/core/drivers/libevent2_tcp.d:651
651	../../../../root/.dub/packages/vibe-d-0.7.22/source/vibe/core/drivers/libevent2_tcp.d: 没有那个文件或目录.(means no such directory. The app is running on server, the server have no source code.)
	in ../../../../root/.dub/packages/vibe-d-0.7.22/source/vibe/core/drivers/libevent2_tcp.d
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.107.el6.x86_64 keyutils-libs-1.4-4.el6.x86_64 krb5-libs-1.10.3-10.el6.x86_64 libcom_err-1.41.12-14.el6.x86_64 libselinux-2.0.94-5.3.el6.x86_64 openssl-1.0.1e-30.el6_6.4.x86_64 zlib-1.2.3-29.el6.x86_64

Here is the code of "libevent2_tcp.d:651"

if (ctx.readOwner && ctx.readOwner.running) {
	logTrace("resuming corresponding task%s...", ex is null ? "" : " with exception");
	if (ctx.readOwner.fiber.state == Fiber.State.EXEC) ctx.exception = ex;
	else ctx.core.resumeTask(ctx.readOwner, ex);
}
if (ctx.writeOwner && ctx.writeOwner != ctx.readOwner && ctx.writeOwner.running) {
	logTrace("resuming corresponding task%s...", ex is null ? "" : " with exception");
	if (ctx.writeOwner.fiber.state == Fiber.State.EXEC) ctx.exception = ex;
	else ctx.core.resumeTask(ctx.writeOwner, ex); //LINE 651
}

Re: App crashed with segfault.

I got the lastest error info in my IDE:

Handling of connection failed: Operating on closed TCPConnection.
Task terminated with unhandled exception: Trying to acquire a TCP connection that is currently owned.
core.exception.AssertError@../../../zhmt/.dub/packages/vibe-d-0.7.22/source/vibe/core/drivers/libevent2_tcp.d(132): Trying to acquire a TCP connection that is currently owned.
----------------
5   ezsock                              0x000000010a186563 void vibe.core.drivers.libevent2_tcp.Libevent2TCPConnection.acquire() + 239
6   ezsock                              0x000000010a18685a void vibe.core.drivers.libevent2_tcp.Libevent2TCPConnection.close() + 126
7   ezsock                              0x000000010a0cdae8 void ezsockacount.SockServer.SockServer.handleConn(vibe.core.net.TCPConnection) + 200
8   ezsock                              0x000000010a0cda1a D12ezsockacount10SockServer10SockServer6listenMFZ45__T9__lambda1TC4vibe4core3net13TCPConnectionZ9__lambda1MFC4vibe4core3net13TCPConnectionZv + 34
9   ezsock                              0x000000010a188b5f void vibe.core.drivers.libevent2_tcp.ClientTask.execute() + 1203
10  ezsock                              0x000000010a09d258 void vibe.core.core.makeTaskFuncInfo!(void delegate()).makeTaskFuncInfo(ref void delegate()).callDelegate(vibe.core.core.TaskFuncInfo*) + 120
11  ezsock                              0x000000010a16edab void vibe.core.core.CoreTask.run() + 395
12  ezsock                              0x000000010a258d79 void core.thread.Fiber.run() + 49
13  ezsock                              0x000000010a25891a fiber_entryPoint + 98
14  ???                                 0x0000000000000000 0x0 + 0
=== Bypassed ===
std.exception.ErrnoException@(0): Error reading from socket 207 (Connection reset by peer)
----------------
5   ezsock                              0x000000010a186c69 @property ulong vibe.core.drivers.libevent2_tcp.Libevent2TCPConnection.leastSize() + 357
6   ezsock                              0x000000010a186af3 @property bool vibe.core.drivers.libevent2_tcp.Libevent2TCPConnection.empty() + 95
7   ezsock                              0x000000010a1ad52d void vibe.core.stream.OutputStream.writeDefault(vibe.core.stream.InputStream, ulong) + 153
8   ezsock                              0x000000010a187827 void vibe.core.drivers.libevent2_tcp.Libevent2TCPConnection.write(vibe.core.stream.InputStream, ulong) + 203
9   ezsock                              0x000000010a0cc3e2 void ezsockacount.NetUtil.NetUtil.forward(vibe.core.net.TCPConnection, vibe.core.net.TCPConnection) + 170
10  ezsock                              0x000000010a0cdb95 void ezsockacount.SockServer.SockServer.handleConnect(vibe.core.net.TCPConnection, ref sock_types.Cmd) + 157
11  ezsock                              0x000000010a0cdace void ezsockacount.SockServer.SockServer.handleConn(vibe.core.net.TCPConnection) + 174
12  ezsock                              0x000000010a0cda1a D12ezsockacount10SockServer10SockServer6listenMFZ45__T9__lambda1TC4vibe4core3net13TCPConnectionZ9__lambda1MFC4vibe4core3net13TCPConnectionZv + 34
13  ezsock                              0x000000010a188b5f void vibe.core.drivers.libevent2_tcp.ClientTask.execute() + 1203
14  ezsock                              0x000000010a09d258 void vibe.core.core.makeTaskFuncInfo!(void delegate()).makeTaskFuncInfo(ref void delegate()).callDelegate(vibe.core.core.TaskFuncInfo*) + 120
15  ezsock                              0x000000010a16edab void vibe.core.core.CoreTask.run() + 395
16  ezsock                              0x000000010a258d79 void core.thread.Fiber.run() + 49
17  ezsock                              0x000000010a25891a fiber_entryPoint + 98
18  ???                                 0x0000000000000000 0x0 + 0
=== ~Bypassed ===
Error executing command run: Program exited with code 1

Re: App crashed with segfault.

It seems that the forward method caused the error:

static void forward(TCPConnection client,TCPConnection remote)
{
	auto wtask = runTask({
			remote.write(client);
		});
	client.write(remote);
	// wait for the tasks to finish
	wtask.join();
}

Re: App crashed with segfault.

Runtask may be accessing 'remote' on a different thread after remote has been closed by score (exit).
Just a thought.

On Thu, 12 Mar 2015 06:05:03 GMT, zhmt wrote:

It seems that the forward method caused the error:

static void forward(TCPConnection client,TCPConnection remote)
{
	auto wtask = runTask({
			remote.write(client);
		});
	client.write(remote);
	// wait for the tasks to finish
	wtask.join();
}


Re: App crashed with segfault.

On Fri, 13 Mar 2015 03:32:58 GMT, Flamencofantasy wrote:

Runtask may be accessing 'remote' on a different thread after remote has been closed by score (exit).
Just a thought.

On Thu, 12 Mar 2015 06:05:03 GMT, zhmt wrote:

It seems that the forward method caused the error:

static void forward(TCPConnection client,TCPConnection remote)
{
	auto wtask = runTask({
			remote.write(client);
		});
	client.write(remote);
	// wait for the tasks to finish
	wtask.join();
}



According to the source code of vibe:

private void acquire()
	{
		assert(m_ctx, "Trying to acquire a closed TCP connection.");
		assert(m_ctx.readOwner == Task() && m_ctx.writeOwner == Task(), "Trying to acquire a TCP connection that is currently owned.");
		m_ctx.readOwner = m_ctx.writeOwner = Task.getThis();
	}

It assumes that the reader and writer of a connection should be the same fiber,
but in my scene, it is forwarding in both directions, so, the reader and writer fibers are not the same one.

But how to handle in this scene?

Authors of vibe, will you help me?

Re: App crashed with segfault.

Am 13.03.2015 um 07:32 schrieb zhmt:

On Fri, 13 Mar 2015 03:32:58 GMT, Flamencofantasy wrote:

Runtask may be accessing 'remote' on a different thread after remote has been closed by score (exit).
Just a thought.

On Thu, 12 Mar 2015 06:05:03 GMT, zhmt wrote:

It seems that the forward method caused the error:

static void forward(TCPConnection client,TCPConnection remote)
{
	auto wtask = runTask({
			remote.write(client);
		});
	client.write(remote);
	// wait for the tasks to finish
	wtask.join();
}



According to the source code of vibe:

private void acquire()
	{
		assert(m_ctx, "Trying to acquire a closed TCP connection.");
		assert(m_ctx.readOwner == Task() && m_ctx.writeOwner == Task(), "Trying to acquire a TCP connection that is currently owned.");
		m_ctx.readOwner = m_ctx.writeOwner = Task.getThis();
	}

It assumes that the reader and writer of a connection should be the same fiber,
but in my scene, it is forwarding in both directions, so, the reader and writer fibers are not the same one.

But how to handle in this scene?

Authors of vibe, will you help me?

The code you have is supposed to work in general, but it seems like the
closing sequence produces events in an unexpected order. I'll try to
reproduce the issue.

Re: App crashed with segfault.

On Fri, 13 Mar 2015 08:34:49 +0100, Sönke Ludwig wrote:

Am 13.03.2015 um 07:32 schrieb zhmt:

On Fri, 13 Mar 2015 03:32:58 GMT, Flamencofantasy wrote:

Runtask may be accessing 'remote' on a different thread after remote has been closed by score (exit).
Just a thought.

On Thu, 12 Mar 2015 06:05:03 GMT, zhmt wrote:

It seems that the forward method caused the error:

static void forward(TCPConnection client,TCPConnection remote)
{
	auto wtask = runTask({
			remote.write(client);
		});
	client.write(remote);
	// wait for the tasks to finish
	wtask.join();
}



According to the source code of vibe:

private void acquire()
	{
		assert(m_ctx, "Trying to acquire a closed TCP connection.");
		assert(m_ctx.readOwner == Task() && m_ctx.writeOwner == Task(), "Trying to acquire a TCP connection that is currently owned.");
		m_ctx.readOwner = m_ctx.writeOwner = Task.getThis();
	}

It assumes that the reader and writer of a connection should be the same fiber,
but in my scene, it is forwarding in both directions, so, the reader and writer fibers are not the same one.

But how to handle in this scene?

Authors of vibe, will you help me?

The code you have is supposed to work in general, but it seems like the
closing sequence produces events in an unexpected order. I'll try to
reproduce the issue.

I uploaded all my code here:
https://raw.githubusercontent.com/ezsock5/ezsock5/master/ezsock.src.zip

you could download it. It is a sock4/sock5 proxy, run it on your pc, configure network configuration of your browser(IE/Firefox) , change the proxy configuration as below:
ip :127.0.0.1, port 9990, socks4 or socks5

And then view some web pages, after a few minutes, this bug will occure again.

It typically happens in SockServer.d.

I hope I've supplied enough information. If not, reply here.

Re: App crashed with segfault.

I've started a new branch with the required fixes and a test included:

https://github.com/rejectedsoftware/vibe.d/tree/inter_task_fixes

Those fixes won't get into the next release yet, because they required a few deeper changes that need more testing first.

BTW, for proper bi-directional connection close behavior you should add explicit close requests to the forwarding function. See the example for reference: https://github.com/rejectedsoftware/vibe.d/blob/intertaskfixes/tests/tcpproxy/source/app.d#L55>

Pages: 1 2