Github user AiHe commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6338#discussion_r33499870
  
    --- Diff: python/pyspark/rdd.py ---
    @@ -121,15 +121,30 @@ def _parse_memory(s):
     
     
     def _load_from_socket(port, serializer):
    -    sock = socket.socket()
    -    sock.settimeout(3)
    -    try:
    -        sock.connect(("localhost", port))
    -        rf = sock.makefile("rb", 65536)
    -        for item in serializer.load_stream(rf):
    -            yield item
    -    finally:
    -        sock.close()
    +    sock = None
    +    # Support for both IPv4 and IPv6.
    +    # On most of IPv6-ready systems, IPv6 will take precedence.
    +    for res in socket.getaddrinfo("localhost", port, socket.AF_UNSPEC, 
socket.SOCK_STREAM):
    +        af, socktype, proto, canonname, sa = res
    +        try:
    +            sock = socket.socket(af, socktype, proto)
    +            sock.settimeout(3)
    +            sock.connect(sa)
    +        except socket.error:
    +            sock = None
    +            continue
    +        break
    +    if sock:
    +        try:
    +            rf = sock.makefile("rb", 65536)
    +            for item in serializer.load_stream(rf):
    +                yield item
    +        except socket.error:
    +            raise Exception("encounter error when connecting to socket 
server")
    +        finally:
    +            sock.close()
    +    else:
    +        raise Exception("could not open socket")
    --- End diff --
    
    Hi Davies, you mean the "else branch"? I think it will throw the exception 
once connections in both IPV4 and IPV6 cannot be established. What's the 
benefit to move the "else" branch?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to