Skip to content

最新的2.0.8版本在linux中会出现Name or service not known错误 #50

Description

@zhaowgit

升级2.0.8版本后linux系统上的连接出现问题,报错:Error occurs when opening session pool. Client pool size is not equal to the expected size. Client pool size: 0, expected size: 1, Please check the server status
但是windows上的连接没有问题。
通过日志发现如下错误:
warn: IoTDB[0]
Failed to create connection 1/1 to 192.168.1.10:6667
Thrift.Transport.TTransportException: Name or service not known
---> System.Net.Sockets.SocketException (00000005, 0xFFFDFFFF): Name or service not known
at System.Net.Dns.GetHostEntryOrAddressesCore(IPAddress address, Boolean justAddresses, AddressFamily addressFamily, Nullab>
at System.Net.Dns.GetHostEntry(String hostNameOrAddress, AddressFamily family)
at Thrift.Transport.Client.TSocketTransport..ctor(String host, Int32 port, TConfiguration config, Int32 timeout)
--- End of inner exception stack trace ---
at Thrift.Transport.Client.TSocketTransport..ctor(String host, Int32 port, TConfiguration config, Int32 timeout)
at Apache.IoTDB.SessionPool.CreateAndOpen(String host, Int32 port, Boolean enableRpcCompression, Int32 timeout, Boolean use>
at Apache.IoTDB.SessionPool.Open(CancellationToken cancellationToken)

检查发现Apache.IoTDB.SessionPool.CreateAndOpen调用了public TSocketTransport(string host, int port, TConfiguration config, int timeout = 0),这个构造函数直接调用了Dns.GetHostEntry去解析IP地址。
.NET 的 Dns.GetHostAddresses/GetHostEntry 最终依赖底层操作系统的名称解析 API;不同平台的行为并不完全一致。
在linux中 Dns.GetHostEntry(string) 遇到 IP 字符串时,不是简单返回这个 IP,而是会:
先把字符串解析成 IP;
对这个 IP 做一次反向解析拿主机名;
再用这个主机名做一次正向解析拿地址列表。
这个过程中任一步失败,都可能抛 SocketException。
在windows中则会宽松很多。
我现在把我的ip地址写道了/etc/hosts中,定义了一个主机名,现在可以正常连接。
但是这在linux中还是很不友好的,建议不要调用public TSocketTransport(string host, int port, TConfiguration config, int timeout = 0),而是使用public TSocketTransport(string hostNameOrIpAddress, int port, bool connectClient, TConfiguration config, int timeout = 0)代替,这个构造函数先判断hostNameOrIpAddress是不是IP地址,是的话直接使用,不是的话再调用Dns.GetHostEntry,这样linux系统就不用定义主机名了。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions