Skip to content
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

Failure in environments without IPv6 support #664

Closed
marcotuna opened this issue Nov 29, 2018 · 27 comments
Closed

Failure in environments without IPv6 support #664

marcotuna opened this issue Nov 29, 2018 · 27 comments

Comments

@marcotuna
Copy link

marcotuna commented Nov 29, 2018

Problem description

Tried to implement GRPC on a project using FreeBSD 11.2 and it throw a core dump, then decided to try the demo project from the grpc repository, core dump, updated the packages to the latest versions, core dump... It compiles with node-gyp without errors apparently. The same steps on Linux works.

Reproduction steps

git clone https://github.com/grpc/grpc
cd grpc/examples/node
npm install
cd dynamic_codegen
node greeter_server.js

Environment

  • OS name, version and architecture: FreeBSD 11.2-RELEASE-p4
  • Node version: v8.12.0
  • Node installation method: pkg install node8
  • If applicable, compiler version: clang 6.0.0
  • Package name and version: [email protected]

Additional context

user@server:/home/user/grpc/examples/node/static_codegen % node greeter_server.js 
Segmentation fault (core dumped)
ls -la
-rw-------  1 user  user  64303104 Nov 29 22:22 node.core
@nicolasnoble
Copy link
Member

Any way to get the stack trace out of your core dump? I'm kind of reluctant to spin a full FreeBSD VM to debug this one.

@marcotuna
Copy link
Author

Here it is the output from gdb

user@server:/home/user/grpc/examples/node/dynamic_codegen % gdb
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd".
(gdb) core node.core 
Core was generated by `node greeter_server.js'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000807c2f1be in ?? ()
(gdb) bt full
#0  0x0000000807c2f1be in ?? ()
No symbol table info available.
#1  0x0000000000000016 in ?? ()
No symbol table info available.
#2  0x0000000805c3d640 in ?? ()
No symbol table info available.
#3  0x0000000807ef8700 in ?? ()
No symbol table info available.
#4  0x0000000807cbe0c9 in ?? ()
No symbol table info available.
#5  0x0000000000000022 in ?? ()
No symbol table info available.
#6  0x0000000000000000 in ?? ()
No symbol table info available

Debug symbols not available?

@nicolasnoble
Copy link
Member

oh, great, no stacktrace visible... groan

Can you try doing npm install --debug ? This should build the extension in debug, leaving symbols on.

@marcotuna
Copy link
Author

I tried this way and now I get some more output:

user@server:/home/user/grpc/examples/node/dynamic_codegen % gdb --args node greeter_server.js 
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
(gdb) run
Starting program: /usr/local/bin/node greeter_server.js
(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...warning: Lowest section in /usr/local/lib/libicudata.so.62 is .hash at 0000000000000120
(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
uv_socket_bind (socket=0x805c23870, addr=0x7fffffffc2c8, len=28, flags=0) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:303
303	      uv_tcp_bind((uv_tcp_t*)uv_socket->handle, (struct sockaddr*)addr, 0);
Current language:  auto; currently c++
(gdb) bt full
#0  uv_socket_bind (socket=0x805c23870, addr=0x7fffffffc2c8, len=28, flags=0) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:303
	uv_socket = (uv_socket_t *) 0x0
	status = <value optimized out>
#1  0x0000000807c6d984 in tcp_server_add_port (s=<value optimized out>, addr=<value optimized out>, port=<value optimized out>) at ../deps/grpc/src/core/lib/iomgr/tcp_server_custom.cc:281
	port_index = 0
	allocated_addr = (grpc_resolved_address *) 0x0
	addr6_v4mapped = {addr = 0x7fffffffc240 "", len = 28}
	wildcard = {addr = 0x7fffffffc2c8 "", len = 28}
	error = <value optimized out>
	sp = <value optimized out>
	socket = (grpc_custom_socket *) 0x805c23870
	sockname_temp = {addr = 0x7fffffffc350 "\v", len = 24}
	family = 28
#2  0x0000000807c5f4f8 in grpc_chttp2_server_add_port (server=<value optimized out>, addr=0x7fffffffc650 "0.0.0.0:50051", args=0x805c276f0, port_num=0x7fffffffc60c) at ../deps/grpc/src/core/ext/transport/chttp2/server/chttp2_server.cc:335
	socket_uuid = Error accessing memory address 0x0: Bad address.
(gdb) 

@nicolasnoble
Copy link
Member

Huh, that's... interesting. The uv_socket is NULL. Why...

I guess we'll have to try and debug it... how did you get nodejs installed exactly? Was it a port or another method?

@marcotuna
Copy link
Author

The NodeJS port is from the official freebsd packages, I even tried the latest version, the same problem.
I am running this inside a FreeBSD Jail, I am going to try this in the main host.

@marcotuna
Copy link
Author

marcotuna commented Nov 29, 2018

On FreeBSD main host (outside jail) runs without any crash, it seems that grpc struggles getting an ip address inside a Jail...
I tried to set static ip address instead of 0.0.0.0 but didn't solve

@murgatroid99
Copy link
Member

I think this may actually be a memory allocation failure, not a failure to get an address. If you can debug the running program, then you can break on tcp_uv.cc:218 and check the value of uv_socket. If it's NULL, then that confirms the most likely allocation failure.

@marcotuna
Copy link
Author

Here's what I've tried:

(gdb) print uv_socket
$1 = (uv_socket_t *) 0x0
(gdb) print addr
$2 = (const grpc_sockaddr *) 0x7fffffffc2c8
(gdb) print socket
$4 = (grpc_custom_socket *) 0x805c237b0
(gdb) print flags
$6 = 0
(gdb) print (uv_tcp_t*)uv_socket->handle
Error accessing memory address 0x170: Bad address.

Why this is happening? That's so weird...

@nicolasnoble
Copy link
Member

@marcotuna but this is from the coredump itself, right? @murgatroid99 was talking about trying to run nodejs within gdb, placing a breakpoint, and getting the values there.

@marcotuna
Copy link
Author

marcotuna commented Nov 30, 2018

I'm having issues setting the breakpoint because of the debug symbols are not present, I already installed with npm install --debug
Inside the build folder I have:

user@server:/home/user/grpc/examples/node/dynamic_codegen % ls -lath /home/user/grpc/examples/node/node_modules/grpc/build/Debug/
total 11584
drwxr-xr-x  5 user  user     9B Nov 29 23:43 obj.target
drwxr-xr-x  4 user  user     4B Nov 29 23:43 .deps
drwxr-xr-x  4 user  user     7B Nov 29 23:43 .
-rwxr-xr-x  1 user  user   8.2M Nov 29 23:43 grpc_node.node
-rw-r--r--  1 user  user   294K Nov 29 23:43 libgpr.a
-rw-r--r--  1 user  user    16M Nov 29 23:43 libgrpc.a
drwxr-xr-x  3 user  user    10B Nov 29 23:42 ..

grpc_node.node seems to be the file causing the issues, starting it causes:

user@server:/home/user/grpc/examples/node/dynamic_codegen % /home/user/grpc/examples/node/node_modules/grpc/build/Debug/grpc_node.node 
Segmentation fault (core dumped)

So I tried the following:

user@server:/home/user/grpc/examples/node/dynamic_codegen % gdb --args node greeter_server.js
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
(gdb) break tcp_uv.cc:218
No symbol table is loaded.  Use the "file" command.
(gdb) file /home/user/grpc/examples/node/node_modules/grpc/build/Debug/grpc_node.node
Reading symbols from /home/user/grpc/examples/node/node_modules/grpc/build/Debug/grpc_node.node...done.
(gdb) break tcp_uv.cc:218
Breakpoint 1 at 0x46402: file ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc, line 218.
(gdb) run
Starting program: /home/user/grpc/examples/node/node_modules/grpc/build/Debug/grpc_node.node greeter_server.js
Breakpoint 1 at 0x1067402: file ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc, line 218.
warning: shared library handler failed to enable breakpoint

Program received signal SIGSEGV, Segmentation fault.
0x0000000001037484 in __do_global_dtors_aux ()
(gdb) 

Probably I am doing something wrong

Edit 1

Running the gdb command as the last time, now prints more output

user@server:/home/user/grpc/examples/node/dynamic_codegen % gdb --args node greeter_server.js
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...(no debugging symbols found)...
(gdb) bt full
No stack.
(gdb) run
Starting program: /usr/local/bin/node greeter_server.js
(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...warning: Lowest section in /usr/local/lib/libicudata.so.62 is .hash at 0000000000000120
(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...
Program received signal SIGSEGV, Segmentation fault.
uv_socket_bind (socket=0x805c23870, addr=0x7fffffffc1f8, len=28, flags=0) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:303
303	      uv_tcp_bind((uv_tcp_t*)uv_socket->handle, (struct sockaddr*)addr, 0);
Current language:  auto; currently c++
(gdb) bt full
#0  uv_socket_bind (socket=0x805c23870, addr=0x7fffffffc1f8, len=28, flags=0) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:303
	uv_socket = (uv_socket_t *) 0x0
	status = 32767
#1  0x0000000807cb0669 in add_socket_to_server (s=0x805dfc1e0, socket=0x805c23870, addr=0x7fffffffc1f8, port_index=0, listener=0x7fffffffc310) at ../deps/grpc/src/core/lib/iomgr/tcp_server_custom.cc:281
	sp = (grpc_tcp_listener *) 0x0
	port = -1
	error = (grpc_error *) 0x805d0c380
	sockname_temp = {addr = 0x7fffffffc000 "\026", len = 96714752}
#2  0x0000000807caffe1 in tcp_server_add_port (s=0x805dfc1e0, addr=0x7fffffffc1f8, port=0x7fffffffc44c) at ../deps/grpc/src/core/lib/iomgr/tcp_server_custom.cc:396
	sp = (grpc_tcp_listener *) 0x0
	socket = (grpc_custom_socket *) 0x805c23870
	addr6_v4mapped = {addr = 0x7fffffffc280 "", len = 28}
	wildcard = {addr = 0x7fffffffc1f8 "", len = 28}
	allocated_addr = (grpc_resolved_address *) 0x0
	sockname_temp = {addr = 0x7fffffffc168 " ��\001", len = 31187232}
	port_index = 0
	error = (grpc_error *) 0x0
	family = 28
#3  0x0000000807caf5f8 in grpc_tcp_server_add_port (s=0x805dfc1e0, addr=0x805c3d640, out_port=0x7fffffffc44c) at ../deps/grpc/src/core/lib/iomgr/tcp_server.cc:41
No locals.
#4  0x0000000807c98c79 in grpc_chttp2_server_add_port (server=0x805cc0380, addr=0x7fffffffca28 "0.0.0.0:50051", args=0x805c276f0, port_num=0x7fffffffc564) at ../deps/grpc/src/core/ext/transport/chttp2/server/chttp2_server.cc:335
	resolved = (grpc_resolved_addresses *) 0x805c27740
	tcp_server = (grpc_tcp_server *) 0x805dfc1e0
	i = 0
	count = 0
	port_temp = 50051
	err = (grpc_error *) 0x0
	state = (server_state *) 0x805c3d6e0
	errors = (grpc_error **) 0x805c284d0
	naddrs = 1
	arg = (const grpc_arg *) 0x0
	socket_uuid = 0
#5  0x0000000807c9b0fe in grpc_server_add_insecure_http2_port (server=0x805cc0380, addr=0x7fffffffca28 "0.0.0.0:50051") at ../deps/grpc/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc:35
	exec_ctx = {_vptr$ExecCtx = 0x807f85a98, closure_list_ = {head = 0x0, tail = 0x0}, combiner_data_ = {active_combiner = 0x0, last_combiner = 0x0}, flags_ = 1, starting_cpu_ = 1, now_is_valid_ = false, now_ = 0, static exec_ctx_ = <optimized out>, last_exec_ctx_ = 0x0}
	port_num = -1
	err = (grpc_error *) 0x7fffffffc598
#6  0x0000000807c35123 in grpc::node::Server::AddHttp2Port (info=@0x7fffffffceb0) at ../ext/server.cc:265
	server = (grpc::node::Server *) 0x805c236f0
	creds_object = (grpc::node::ServerCredentials *) 0x805d132c0
	creds = (grpc_server_credentials *) 0x0
	port = 8
#7  0x0000000807c1a779 in Nan::imp::FunctionCallbackWrapper (info=@0x7fffffffcf90) at nan_callbacks_12_inl.h:176
	obj = {val_ = 0x7fffffffd030}
	callback = 0x807c34fa0 <grpc::node::Server::AddHttp2Port(Nan::FunctionCallbackInfo<v8::Value> const&)>
	cbinfo = {info_ = @0x7fffffffcf90, data_ = {val_ = 0x805ceb880}, static kHolderIndex = <optimized out>, static kIsolateIndex = <optimized out>, static kReturnValueDefaultValueIndex = <optimized out>, static kReturnValueIndex = <optimized out>, static kDataIndex = 0, static kCalleeIndex = <optimized out>, 
  static kContextSaveIndex = <optimized out>, static kArgsLength = <optimized out>}

Edit 2

(gdb) break tcp_uv.cc:218
Breakpoint 1 at 0x807e46402: file ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc, line 218.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /usr/local/bin/node greeter_server.js
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
warning: Lowest section in /usr/local/lib/libicudata.so.62 is .hash at 0000000000000120
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Error in re-setting breakpoint 1:
No source file named tcp_uv.cc.
Breakpoint 1 at 0x807c46402: file ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc, line 218.

Breakpoint 1, uv_socket_init (socket=0x805c238d0, domain=28) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:218
218	  grpc_error* error = uv_socket_init_helper(uv_socket, domain);
(gdb) print uv_socket
$1 = (uv_socket_t *) 0x805c3c000
Breakpoint 1, uv_socket_init (socket=0x805c23540, domain=28) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:218
218	  grpc_error* error = uv_socket_init_helper(uv_socket, domain);
(gdb) bt full
#0  uv_socket_init (socket=0x805c23540, domain=28) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:218
	uv_socket = (uv_socket_t *) 0x805d9e200
	error = (grpc_error *) 0x80831c696
#1  0x00000008082ab341 in tcp_server_add_port (s=0x805d7d220, addr=0x7fffffffc348, port=0x7fffffffc56c) at ../deps/grpc/src/core/lib/iomgr/tcp_server_custom.cc:393
	sp = (grpc_tcp_listener *) 0x0
	socket = (grpc_custom_socket *) 0x805c23540
	addr6_v4mapped = {addr = 0x7fffffffc3d0 "", len = 28}
	wildcard = {addr = 0x7fffffffc348 "", len = 28}
	allocated_addr = (grpc_resolved_address *) 0x0
	sockname_temp = {addr = 0x7fffffffc2b8 " ��\001", len = 31187232}
	port_index = 0
	error = (grpc_error *) 0x0
	family = 28
#2  0x00000008082aa988 in grpc_tcp_server_add_port (s=0x805d7d220, addr=0x805c3d640, out_port=0x7fffffffc56c) at ../deps/grpc/src/core/lib/iomgr/tcp_server.cc:41
No locals.
#3  0x0000000808298752 in grpc_chttp2_server_add_port (server=0x805cc0380, addr=0x7fffffffcab8 "0.0.0.0:50051", args=0x805c276f0, port_num=0x7fffffffc5f4) at ../deps/grpc/src/core/ext/transport/chttp2/server/chttp2_server.cc:293
	resolved = (grpc_resolved_addresses *) 0x805dfed50
	tcp_server = (grpc_tcp_server *) 0x805d7d220
	i = 0
	count = 0
	port_temp = 50051
	err = (grpc_error *) 0x0
	state = (server_state *) 0x805c3d6e0
	errors = (grpc_error **) 0x807829010
	naddrs = 1
#4  0x000000080829a49e in grpc_server_add_insecure_http2_port (server=0x805cc0380, addr=0x7fffffffcab8 "0.0.0.0:50051") at ../deps/grpc/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc:35
	exec_ctx = {_vptr$ExecCtx = 0x80856e5e8, closure_list_ = {head = 0x0, tail = 0x0}, combiner_data_ = {active_combiner = 0x0, last_combiner = 0x0}, flags_ = 1, starting_cpu_ = 3, now_is_valid_ = false, now_ = 0, static exec_ctx_ = <optimized out>, last_exec_ctx_ = 0x0}
	port_num = -1
	err = (grpc_error *) 0x7fffffffc628
#5  0x0000000808234cc3 in grpc::node::Server::AddHttp2Port (info=@0x7fffffffcf40) at ../ext/server.cc:265
	server = (grpc::node::Server *) 0x805c236f0
	creds_object = (grpc::node::ServerCredentials *) 0x805d133a0
	creds = (grpc_server_credentials *) 0x0
	port = 8
#6  0x000000080821a319 in Nan::imp::FunctionCallbackWrapper (info=@0x7fffffffd020) at nan_callbacks_12_inl.h:176
	obj = {val_ = 0x7fffffffd0c0}
	callback = 0x808234b40 <grpc::node::Server::AddHttp2Port(Nan::FunctionCallbackInfo<v8::Value> const&)>
	cbinfo = {info_ = @0x7fffffffd020, data_ = {val_ = 0x805ceb880}, static kHolderIndex = <optimized out>, static kIsolateIndex = <optimized out>, static kReturnValueDefaultValueIndex = <optimized out>, static kReturnValueIndex = <optimized out>, static kDataIndex = 0, static kCalleeIndex = <optimized out>, 
  static kContextSaveIndex = <optimized out>, static kArgsLength = <optimized out>}
#7  0x00000000008acd2d in v8::internal::FunctionCallbackArguments::Call ()

Edit 3 (Created new FreeBSD Jail)

Breakpoint 1, uv_socket_init (socket=0x805c23810, domain=28) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:218
218	  grpc_error* error = uv_socket_init_helper(uv_socket, domain);
(gdb) print uv_socket
$1 = (uv_socket_t *) 0x805d9e200
(gdb) s
uv_socket_init_helper (uv_socket=0x805d9e200, domain=28) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:189
189	  uv_tcp_t* tcp = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t));
(gdb) print uv_socket
$2 = (uv_socket_t *) 0x805d9e200
(gdb) s
gpr_malloc (size=256) at ../deps/grpc/src/core/lib/gpr/alloc.cc:54
54	  GPR_TIMER_SCOPE("gpr_malloc", 0);
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
56	  if (size == 0) return nullptr;
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
57	  p = g_alloc_functions.malloc_fn(size);
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
58	  if (!p) {
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
61	  return p;
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
62	}
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
uv_socket_init_helper (uv_socket=0x805d9e200, domain=28) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:189
189	  uv_tcp_t* tcp = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t));
(gdb) print uv_socket
$3 = (uv_socket_t *) 0x805d9e200
(gdb) s
190	  uv_socket->handle = tcp;
(gdb) print uv_socket
$4 = (uv_socket_t *) 0x805d9e200
(gdb) s
191	  int status = uv_tcp_init_ex(uv_default_loop(), tcp, (unsigned int)domain);
(gdb) print uv_socket
$5 = (uv_socket_t *) 0x805d9e200
(gdb) s
0x0000000804c3be60 in pthread_timedjoin_np () from /lib/libthr.so.3
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
Single stepping until exit from function pthread_timedjoin_np, 
which has no line number information.
0x0000000804c357a0 in pthread_getspecific () from /lib/libthr.so.3
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
Single stepping until exit from function pthread_getspecific, 
which has no line number information.
0x0000000804c3be3c in pthread_timedjoin_np () from /lib/libthr.so.3
(gdb) print uv_socket
No symbol "uv_socket" in current context.
(gdb) s
Single stepping until exit from function pthread_timedjoin_np, 
which has no line number information.

Program received signal SIGSEGV, Segmentation fault.
uv_socket_bind (socket=0x805c23810, addr=0x7fffffffc348, len=28, flags=0) at ../deps/grpc/src/core/lib/iomgr/tcp_uv.cc:303
303	      uv_tcp_bind((uv_tcp_t*)uv_socket->handle, (struct sockaddr*)addr, 0);
(gdb) print uv_socket
$6 = (uv_socket_t *) 0x0

@nicolasnoble nicolasnoble changed the title GRPC on FreeBSD 11.2 (Core.dump) Segfault when running grpc-node in a FreeBSD jail Nov 30, 2018
@murgatroid99
Copy link
Member

It now looks like the actual failure here is libuv failing to initialize its handle object, which may be happening because you are not able to create sockets at all, or because you cannot create sockets with the given IP version. Since you have tried 0.0.0.0, you may instead have luck with [::], which will force IPv6. If that doesn't work, it is likely that you cannot create sockets at all.

This has exposed a bug in how errors in that function are getting handled, but even after we fix that you will just see the same failure with a nicer message.

@nicolasnoble
Copy link
Member

If you can dtruss or dtrace the node process, and upload the resulting log somewhere, we'd be able to see which actual error code was returned by the socket creation code.

@marcotuna
Copy link
Author

marcotuna commented Nov 30, 2018

@murgatroid99 I tried changing the IP Addresses in the configuration with IPV4 and/or IPV6 and no results so far...
@nicolasnoble Unfortunately FreeBSD does not allow me to run dtrace inside a Jail, only on the main host (however on the main host I don't have this issue).

I tried so far enabling some features regarding socket's limitation on a FreeBSD Jail such as allow.raw_sockets and allow.socket_af
https://www.freebsd.org/cgi/man.cgi?query=jail&sektion=8&apropos=0&manpath=FreeBSD+11.2-RELEASE+and+Ports
Adding more network interfaces to the jail
Testing on different machines (running FreeBSD inside a Jail)
This is only happening with GRPC, I can run other kind of services such as Webserver's, custom app's, databases...

No results so far

Edit 1

I was able to generate with truss and the results are interesting... (Attached)
truss -o /tmp/truss_node_grpc.txt node greeter_server.js
truss_node_grpc.txt

socket(PF_INET6,SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK,0) ERR#43 'Protocol not supported'

I tried disabling IPV6 and still, it keeps using PF_INET6, why?? Because it's compiled on Kernel maybe?

Edit 2

I added an IPV6 address to the Jail and GRPC starts! But what's weird is that I've set a static ip address to IPV4, i'm not even listening to the IPV6 ip. So, this leaves me to conclude that when GRPC detects that the kernel has IPV6 support, even without having an IPV6 address assigned to any network interface it will use PF_INET6

@nicolasnoble
Copy link
Member

Right, I know what's going on here. We're supposed to be creating dual stack sockets first, and then fallback on IPv4 only if this failed. But since we're not checking the result, we never realize that the dual stack socket creation failed.

This is a genuine bug.

@nicolasnoble nicolasnoble changed the title Segfault when running grpc-node in a FreeBSD jail Failure in environments without IPv6 support Nov 30, 2018
@nicolasnoble
Copy link
Member

nicolasnoble commented Nov 30, 2018

It's actually simple to reproduce under plain Linux:

# sysctl -w net.ipv6.conf.all.disable_ipv6=1

@fredantell
Copy link

I believe I was experiencing this exact same issue only recently realizing what was wrong last night with the help of a colleague. For me, code ran fine on my host machine and then failed in docker when ipv6 was not enabled. I did notice that forcing the package I was using on to [email protected] didn't suffer the same issue and my code finally ran as expected.

@marcotuna
Copy link
Author

When is there going to be a fix for this?

@nicolasnoble
Copy link
Member

@marcotuna have you tried 1.17.0-pre1?

@marcotuna
Copy link
Author

marcotuna commented Dec 5, 2018

@nicolasnoble, yes I tried with that release. Even when I started this issue I had tested with that release version. I tried just now just to check if the problem still persist and it does.

@nicolasnoble
Copy link
Member

Ah, sorry. I was confused because of @fredantell's update.

@sdd
Copy link

sdd commented Sep 12, 2019

I'm still experiencing this bug on grpc-node v1.23.3. As with @fredantell , I'm experiencing this on a docker container (AWS ECS) with ipv6 disabled.

I see the following from strace:

write(2, "I0912 11:42:11.051499110     111"..., 98I0912 11:42:11.051499110     111 server.cc:1024]             grpc_server_create(0x35ba890, (nil))
) = 98
write(2, "I0912 11:42:11.051731800     111"..., 147I0912 11:42:11.051731800     111 server.cc:1007]             grpc_server_register_completion_queue(server=0x36356a0, cq=0x3653bd0, reserved=(nil))
) = 147
write(2, "I0912 11:42:11.052408113     111"..., 139I0912 11:42:11.052408113     111 server_chttp2.cc:34]        grpc_server_add_insecure_http2_port(server=0x36356a0, addr=192.168.13.4:6008)
) = 139
write(2, "I0912 11:42:11.052514181     111"..., 131I0912 11:42:11.052514181     111 tcp_server_custom.cc:382]   SERVER 0x36d6370 add_port [::ffff:192.168.13.4]:6008 error="No Error"
) = 131
socket(AF_INET6, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = -1 EAFNOSUPPORT (Address family not supported by protocol)
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x170} ---

The segfault happens due to uv_socket being null at the point where uv_socket->handle is attempted here https://github.com/grpc/grpc/blob/master/src/core/lib/iomgr/tcp_uv.cc#L301

As you can see, I'm specifying an ipv4 address, 192.168.13.4:6008. By the time we get to here the address now shows as [::ffff:192.168.13.4]:6008

@sdd
Copy link

sdd commented Sep 12, 2019

It looks like all ipv4 interfaces get cast to ipv6 here: https://github.com/grpc/grpc/blob/master/src/core/lib/iomgr/tcp_server_custom.cc#L366

So it looks like it is impossible to start grpc-node and bind to a port on a system where IPv6 is disabled. Is that correct?

@abogosyan
Copy link

abogosyan commented Jan 21, 2020

We have the same issue at Centos7 when IPV6 disabled, if we try to create grpc server on IPV4 address we are getting error:

server_chttp2.cc:40] {"created":"@1579610522.002391836","description":"No address added out of total 1 resolved","file":"../deps/grpc/src/core/ext/transport/chttp2/server/chttp2_server.cc","file_line":394,"referenced_errors":[{"created":"@1579610522.002385260","description":"Failed to add port to server","file":"../deps/grpc/src/core/lib/iomgr/tcp_server_custom.cc","file_line":404,"referenced_errors":[{"created":"@1579610522.002372812","description":"Failed to initialize UV tcp handle","file":"../deps/grpc/src/core/lib/iomgr/tcp_uv.cc","file_line":72,"grpc_status":14,"os_error":"address family not supported"}]}]}

If we enable IPV6 support (kernel module + sysctl.conf) then it works

orgads added a commit to orgads/grpc-node that referenced this issue Mar 30, 2020
This happens when a device doesn't have IPv6 address, but the endpoint
address is resolved to both IPv4 and IPv6 addresses.

The automatic attempt to reconnect that fails is detected as another channel
failure, which leads the load balancer to abort the connection.

Fixes grpc#664 and grpc#692
@trombini
Copy link

We face the same issue with grpc-node version 1.24.4. Are there any plans to address this issue? Does anyone know a working workaround?

@murgatroid99
Copy link
Member

I wouldn't expect a fix in the near future. The grpc package is going to be deprecated in April 2021, so I suggest switching to @grpc/grpc-js, which will be actively developed going forward.

@murgatroid99
Copy link
Member

The grpc package is now officially deprecated. I don't expect to fix this problem in that package.

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

Successfully merging a pull request may close this issue.

7 participants