From a97fd13cb383f65db70f78ad88c6c7b550e540c7 Mon Sep 17 00:00:00 2001 From: CritasWang Date: Mon, 20 Apr 2026 18:48:27 +0800 Subject: [PATCH] Fix DNS resolution failure on Linux when host is an IP address (#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. --- src/Apache.IoTDB/SessionPool.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Apache.IoTDB/SessionPool.cs b/src/Apache.IoTDB/SessionPool.cs index 8d42282..971a0d7 100644 --- a/src/Apache.IoTDB/SessionPool.cs +++ b/src/Apache.IoTDB/SessionPool.cs @@ -21,6 +21,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; @@ -450,9 +451,19 @@ public async Task GetTimeZone() private async Task CreateAndOpen(string host, int port, bool enableRpcCompression, int timeout, bool useSsl, string cert, string sqlDialect, string database, CancellationToken cancellationToken = default) { - TTransport socket = useSsl ? - new TTlsSocketTransport(host, port, null, timeout, new X509Certificate2(File.ReadAllBytes(cert))) : - new TSocketTransport(host, port, null, timeout); + TTransport socket; + if (IPAddress.TryParse(host, out var ipAddress)) + { + socket = useSsl + ? new TTlsSocketTransport(ipAddress, port, null, timeout, new X509Certificate2(File.ReadAllBytes(cert))) + : new TSocketTransport(ipAddress, port, null, timeout); + } + else + { + socket = useSsl + ? new TTlsSocketTransport(host, port, null, timeout, new X509Certificate2(File.ReadAllBytes(cert))) + : new TSocketTransport(host, port, null, timeout); + } var transport = new TFramedTransport(socket);