Giter Site home page Giter Site logo

IPV6-Bug about nlog HOT 9 CLOSED

nlog avatar nlog commented on May 11, 2024
IPV6-Bug

from nlog.

Comments (9)

304NotModified avatar 304NotModified commented on May 11, 2024

proposed fix from link:

Add

public bool IsIPv6Supported { get { return false; } }

replace host.AddressList[0] with

foreach (IPAddress address in host.AddressList)
{
    if ((address.AddressFamily ==
        System.Net.Sockets.AddressFamily.InterNetworkV6) &&
        !IsIPv6Supported) 
        continue;

    return address;
}

current code NetworkSender.cs

        /// <summary>
        /// Parses the URI into an endpoint address.
        /// </summary>
        /// <param name="uri">The URI to parse.</param>
        /// <param name="addressFamily">The address family.</param>
        /// <returns>Parsed endpoint.</returns>
        protected virtual EndPoint ParseEndpointAddress(Uri uri, AddressFamily addressFamily)
        {
#if SILVERLIGHT
            return new DnsEndPoint(uri.Host, uri.Port, addressFamily);
#else
            switch (uri.HostNameType)
            {
                case UriHostNameType.IPv4:
                case UriHostNameType.IPv6:
                    return new IPEndPoint(IPAddress.Parse(uri.Host), uri.Port);

                default:
                    {
                        var addresses = Dns.GetHostEntry(uri.Host).AddressList;
                        foreach (var addr in addresses)
                        {
                            if (addr.AddressFamily == addressFamily || addressFamily == AddressFamily.Unspecified)
                            {
                                return new IPEndPoint(addr, uri.Port);
                            }
                        }

                        throw new IOException("Cannot resolve '" + uri.Host + "' to an address in '" + addressFamily + "'");
                    }
            }
#endif
        }

Not sure if we should use AddressFamily instead of IsIPv6Supported

from nlog.

304NotModified avatar 304NotModified commented on May 11, 2024

@mikhail-barg can you help us in closing this one?

from nlog.

mikhail-barg avatar mikhail-barg commented on May 11, 2024

I don't think I have any IPv6 setups within reach, but I'll check tomorrow.

Also I'm not sure what exact configuration is causing the problem. I'm not convenient with IPv6 addressing, but I assume ::1 is a localhost, so both sender and receiver should be on a same machine, or I'm missing something in the original post?

from nlog.

304NotModified avatar 304NotModified commented on May 11, 2024

@mikhail-barg Is this something you could test? Testing with ::1 seems OK to me.

from nlog.

mikhail-barg avatar mikhail-barg commented on May 11, 2024

I will see if I could check this. I don't have any IPv6 setup at my work, and at home I don't have any network message receivers, so I'll have to write something myself.

from nlog.

304NotModified avatar 304NotModified commented on May 11, 2024

@mikhail-barg any change to test this?

Everyone has ::1 (localhost) on his machine?

from nlog.

mikhail-barg avatar mikhail-barg commented on May 11, 2024

Sorry, I'm overloaded with work and literally have no free time currently. I'll do what I can when I have some time, but not sure if I could make it in time to get into 4.3

from nlog.

mikhail-barg avatar mikhail-barg commented on May 11, 2024

I finally found time to check the issue. The original post does not contain too much info on reproducing the problem (here are working links to original post:
http://nlog-forum.1685105.n2.nabble.com/IPV6-Bug-tt1685313.html#none
https://sourceforge.net/p/nlog/mailman/message/1603760/ )

I assumed that the Network target was used with TCP protocol. And also I decided to not try installing Chainsaw or nlog-viewer, but to write some simple TCP-listener.

Here are the results:

when listening to 127.0.0.1:

  • logging to tcp://127.0.0.1 -> OK;
  • logging to tcp4://localhost -> OK;
  • logging to tcp://localhost -> fails with System.IO.IOException: Error: ConnectionRefused;

when listening to ::1:

  • logging to tcp://[::1] -> OK;
  • logging to tcp6://localhost -> OK;
  • logging to tcp://localhost -> OK;

So the issue happens when listener listens to IPv4, and logger logs to localhost without explicitly specifying protocol version and system decides to use IPv6 address for it. I'm not sure if this is an original problem though.

I'm also not sure that this problem is related to NLog. If I issue ping localhost on my machine I get
it resolved to [::1] as well. Specifying explicit usage of tcp4 solves the problem.

As far as I understand the proposed solution, it just forces using IPv4 in case the protocol is not specified explicitly, so it would just result in a symmetrical problem (logging to localhost while listening to [::1] would fail). Considering that IPv6 is "the future", I don't think it's a good idea.

For now I'm attaching the code I've used to test things.
NLogIssue39.zip

from nlog.

304NotModified avatar 304NotModified commented on May 11, 2024

Thanks, will close this as we don't have anything to do here.

from nlog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.