You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/09/06 14:05:26 UTC

[GitHub] [tvm] Goose-Bomb opened a new issue #8937: [Bug] [CPP_RPC] Failed to bind host when using IPv6 addresses

Goose-Bomb opened a new issue #8937:
URL: https://github.com/apache/tvm/issues/8937


   As long as I use the IPv6 address as the host, the C++ RPC program will produce an **Address family not supported by protocol** error.
   
   To reproduce this error, run:
   `./tvm_rpc server --host=:: --port=9090`, this error will occur:
   
   logs:
   ```log
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:96: host        = ::
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:97: port        = 9090
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:98: port_end    = 9099
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:99: tracker     =
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:100: key         =
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:101: custom_addr =
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:102: work_dir    =
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:103: silent      = False
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/main.cc:264: Starting CPP Server, Press Ctrl+C to stop.
   [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/../../src/support/socket.h:265: Warning: Bind failed to :::9090
   terminate called after throwing an instance of 'tvm::runtime::InternalError'
     what():  [20:44:08] /home/nullko/Documents/tvm-vsi_npu/apps/cpp_rpc/../../src/support/socket.h:362: Socket TryBindHost Error:Address family not supported by protocol
   Stack trace:
     [bt] (0) /usr/local/lib/libtvm_runtime.so(tvm::runtime::Backtrace[abi:cxx11]()+0x10) [0xb6ea2f34]
     [bt] (1) ./tvm_rpc(tvm::runtime::detail::LogFatal::Entry::Finalize()+0xcc) [0x4c8204]
     [bt] (2) ./tvm_rpc(tvm::support::Socket::Error(char const*)+0xf8) [0x4d14c8]
     [bt] (3) ./tvm_rpc(tvm::support::Socket::TryBindHost(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int)+0x170) [0x4d0010]
     [bt] (4) ./tvm_rpc(tvm::runtime::RPCServer::Start()+0xe0) [0x4cfa24]
     [bt] (5) ./tvm_rpc(tvm::runtime::RPCServerCreate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool)+0x33c) [0x4cf66c]
     [bt] (6) ./tvm_rpc(RpcServer(int, char**)+0x488) [0x4c7364]
     [bt] (7) ./tvm_rpc(main+0x1bc) [0x4c772c]
     [bt] (8) /lib/arm-linux-gnueabihf/libc.so.6(__libc_start_main+0x99) [0xb6b3c066]
   ```
   
   It seems that the cause is when the socket is created, it by default uses `PF_INET` protocol, without checking what is the actual protocol of the given IP address, as in https://github.com/apache/tvm/blob/7eda4a5342851c9938125086e027d8d1bd5ca298/apps/cpp_rpc/rpc_server.cc#L128 
   
   A quick but ugly workaround could be like this:
   ```c++
     void Start() {
       support::SockAddr addr(host_.c_str(), 0);
       listen_sock_.Create(addr.ss_family());
       my_port_ = listen_sock_.TryBindHost(host_, port_, port_end_);
       LOG(INFO) << "bind to " << host_ << ":" << my_port_;
       listen_sock_.Listen(1);
       std::future<void> proc(std::async(std::launch::async, &RPCServer::ListenLoopProc, this));
       proc.get();
       // Close the listen socket
       listen_sock_.Close();
     }
   ```
   
   Or maybe the socket wrapper could be tweaked to support both IPv4 and IPv6 addresses at the same time, see this post:
   https://www.ibm.com/docs/en/i/7.2?topic=sscaaiic-example-accepting-connections-from-both-ipv6-ipv4-clients


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org