Skip to content

Fix DNS resolution failure on Linux when host is an IP address (#50)#51

Closed
CritasWang wants to merge 1 commit intoapache:mainfrom
CritasWang:fix/issue-50-dns-hostentry
Closed

Fix DNS resolution failure on Linux when host is an IP address (#50)#51
CritasWang wants to merge 1 commit intoapache:mainfrom
CritasWang:fix/issue-50-dns-hostentry

Conversation

@CritasWang
Copy link
Copy Markdown
Contributor

Summary

Fixes #50.

On Linux, SessionPool.CreateAndOpen fails with Thrift.Transport.TTransportException: Name or service not known even when a valid IP literal is supplied. Root cause: the 4-arg TSocketTransport(string host, int port, TConfiguration, int timeout) constructor unconditionally calls Dns.GetHostEntry(host). On Linux, GetHostEntry with an IP string performs reverse lookup first, then re-resolves the returned hostname forward — if either step fails, a SocketException is thrown. Windows is more permissive and hides the bug.

Fix

Pre-parse the host with IPAddress.TryParse:

  • IP literal → use TSocketTransport(IPAddress, …) / TTlsSocketTransport(IPAddress, …, cert) overload, which skips DNS entirely.
  • Hostname → keep the existing string-based path (DNS still resolves normally).

File changed: src/Apache.IoTDB/SessionPool.cs (+14 / -3).

Test plan

  • dotnet build -c Release passes on all target frameworks (net5.0, net6.0, netstandard2.1, netstandard2.0, net461) — 0 errors.
  • Manual smoke: connect with SessionPool(host="<IPv4>", port=6667, …) on a Linux host whose /etc/hosts does not map the IP; expect successful connection.
  • Regression: connect with a hostname (e.g. localhost) — expect unchanged behavior.

…e#50)

TSocketTransport(string host, ...) unconditionally calls Dns.GetHostEntry,
which on Linux performs reverse-then-forward lookup even for literal IPs,
causing 'Name or service not known' SocketException.

Pre-parse host with IPAddress.TryParse and use the IPAddress overloads of
TSocketTransport / TTlsSocketTransport so IP literals bypass DNS entirely.
Hostnames still go through the existing string-based path.
@CritasWang CritasWang closed this Apr 21, 2026
@CritasWang CritasWang deleted the fix/issue-50-dns-hostentry branch April 21, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant