Fix DNS resolution failure on Linux when host is an IP address (#50)#51
Closed
CritasWang wants to merge 1 commit intoapache:mainfrom
Closed
Fix DNS resolution failure on Linux when host is an IP address (#50)#51CritasWang wants to merge 1 commit intoapache:mainfrom
CritasWang wants to merge 1 commit intoapache:mainfrom
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #50.
On Linux,
SessionPool.CreateAndOpenfails withThrift.Transport.TTransportException: Name or service not knowneven when a valid IP literal is supplied. Root cause: the 4-argTSocketTransport(string host, int port, TConfiguration, int timeout)constructor unconditionally callsDns.GetHostEntry(host). On Linux,GetHostEntrywith an IP string performs reverse lookup first, then re-resolves the returned hostname forward — if either step fails, aSocketExceptionis thrown. Windows is more permissive and hides the bug.Fix
Pre-parse the host with
IPAddress.TryParse:TSocketTransport(IPAddress, …)/TTlsSocketTransport(IPAddress, …, cert)overload, which skips DNS entirely.File changed:
src/Apache.IoTDB/SessionPool.cs(+14 / -3).Test plan
dotnet build -c Releasepasses on all target frameworks (net5.0,net6.0,netstandard2.1,netstandard2.0,net461) — 0 errors.SessionPool(host="<IPv4>", port=6667, …)on a Linux host whose/etc/hostsdoes not map the IP; expect successful connection.localhost) — expect unchanged behavior.