prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  is_connection_dropped checks against None but uses False as default value for getattr
  I happened to read this line and the code looks fishy. I did not otherwise verify the potential bug.
  
  See implementation of `is_connection_dropped(conn: socket.socket) -> bool`:
  
  https://github.com/urllib3/urllib3/blob/287052a16a59bcaba5772387de36fa9a49eb8378/src/urllib3/util/connection.py#L19-L23
  
  If there is no property `sock` on `conn`, then we will call `wait_for_read(False, timeout=0.0)`, which e.g. may end up putting the `False` into the iterable passed to `select`.
  
  Since this seemed to never have caused problems, the `sock = getattr(conn, "sock", False)` can probably be replaced with just `sock = conn.sock`.
  
  Alternatives would be to replace the default (last argument of `getattr`) of `False` with `None` or replace the `if sock is None` with `if not sock`.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/urllib3/util/connection.py`
  Content:
  ```
  1 import socket
  2 from typing import List, Optional, Tuple, Union
  3 
  4 from urllib3.exceptions import LocationParseError
  5 
  6 from .wait import wait_for_read
  7 
  8 SOCKET_GLOBAL_DEFAULT_TIMEOUT = socket._GLOBAL_DEFAULT_TIMEOUT  # type: ignore
  9 SocketOptions = List[Tuple[int, int, Union[int, bytes]]]
  10 
  11 
  12 def is_connection_dropped(conn: socket.socket) -> bool:  # Platform-specific
  13     """
  14     Returns True if the connection is dropped and should be closed.
  15 
  16     :param conn:
  17         :class:`http.client.HTTPConnection` object.
  18     """
  19     sock = getattr(conn, "sock", False)
  20     if sock is None:  # Connection already closed (such as by httplib).
  21         return True
  22     # Returns True if readable, which here means it's been dropped
  23     return wait_for_read(sock, timeout=0.0)
  24 
  25 
  26 # This function is copied from socket.py in the Python 2.7 standard
  27 # library test suite. Added to its signature is only `socket_options`.
  28 # One additional modification is that we avoid binding to IPv6 servers
  29 # discovered in DNS if the system doesn't have IPv6 functionality.
  30 def create_connection(
  31     address: Tuple[str, int],
  32     timeout: Optional[float] = SOCKET_GLOBAL_DEFAULT_TIMEOUT,
  33     source_address: Optional[Tuple[str, int]] = None,
  34     socket_options: Optional[SocketOptions] = None,
  35 ) -> socket.socket:
  36     """Connect to *address* and return the socket object.
  37 
  38     Convenience function.  Connect to *address* (a 2-tuple ``(host,
  39     port)``) and return the socket object.  Passing the optional
  40     *timeout* parameter will set the timeout on the socket instance
  41     before attempting to connect.  If no *timeout* is supplied, the
  42     global default timeout setting returned by :func:`socket.getdefaulttimeout`
  43     is used.  If *source_address* is set it must be a tuple of (host, port)
  44     for the socket to bind as a source address before making the connection.
  45     An host of '' or port 0 tells the OS to use the default.
  46     """
  47 
  48     host, port = address
  49     if host.startswith("["):
  50         host = host.strip("[]")
  51     err = None
  52 
  53     # Using the value from allowed_gai_family() in the context of getaddrinfo lets
  54     # us select whether to work with IPv4 DNS records, IPv6 records, or both.
  55     # The original create_connection function always returns all records.
  56     family = allowed_gai_family()
  57 
  58     try:
  59         host.encode("idna")
  60     except UnicodeError:
  61         raise LocationParseError(f"'{host}', label empty or too long") from None
  62 
  63     for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  64         af, socktype, proto, canonname, sa = res
  65         sock = None
  66         try:
  67             sock = socket.socket(af, socktype, proto)
  68 
  69             # If provided, set socket level options before connecting.
  70             _set_socket_options(sock, socket_options)
  71 
  72             if timeout is not SOCKET_GLOBAL_DEFAULT_TIMEOUT:
  73                 sock.settimeout(timeout)
  74             if source_address:
  75                 sock.bind(source_address)
  76             sock.connect(sa)
  77             return sock
  78 
  79         except OSError as e:
  80             err = e
  81             if sock is not None:
  82                 sock.close()
  83                 sock = None
  84 
  85     if err is not None:
  86         raise err
  87 
  88     raise OSError("getaddrinfo returns an empty list")
  89 
  90 
  91 def _set_socket_options(sock: socket.socket, options: Optional[SocketOptions]) -> None:
  92     if options is None:
  93         return
  94 
  95     for opt in options:
  96         sock.setsockopt(*opt)
  97 
  98 
  99 def allowed_gai_family() -> socket.AddressFamily:
  100     """This function is designed to work in the context of
  101     getaddrinfo, where family=socket.AF_UNSPEC is the default and
  102     will perform a DNS search for both IPv6 and IPv4 records."""
  103 
  104     family = socket.AF_INET
  105     if HAS_IPV6:
  106         family = socket.AF_UNSPEC
  107     return family
  108 
  109 
  110 def _has_ipv6(host: str) -> bool:
  111     """ Returns True if the system can bind an IPv6 address. """
  112     sock = None
  113     has_ipv6 = False
  114 
  115     if socket.has_ipv6:
  116         # has_ipv6 returns true if cPython was compiled with IPv6 support.
  117         # It does not tell us if the system has IPv6 support enabled. To
  118         # determine that we must bind to an IPv6 address.
  119         # https://github.com/urllib3/urllib3/pull/611
  120         # https://bugs.python.org/issue658327
  121         try:
  122             sock = socket.socket(socket.AF_INET6)
  123             sock.bind((host, 0))
  124             has_ipv6 = True
  125         except Exception:
  126             pass
  127 
  128     if sock:
  129         sock.close()
  130     return has_ipv6
  131 
  132 
  133 HAS_IPV6 = _has_ipv6("::1")
  134
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/urllib3/util/connection.py b/src/urllib3/util/connection.py
  --- a/src/urllib3/util/connection.py
  +++ b/src/urllib3/util/connection.py
  @@ -16,7 +16,7 @@
       :param conn:
           :class:`http.client.HTTPConnection` object.
       """
  -    sock = getattr(conn, "sock", False)
  +    sock = getattr(conn, "sock", None)
       if sock is None:  # Connection already closed (such as by httplib).
           return True
       # Returns True if readable, which here means it's been dropped
  
verification_info: {"golden_diff": "diff --git a/src/urllib3/util/connection.py b/src/urllib3/util/connection.py\n--- a/src/urllib3/util/connection.py\n+++ b/src/urllib3/util/connection.py\n@@ -16,7 +16,7 @@\n     :param conn:\n         :class:`http.client.HTTPConnection` object.\n     \"\"\"\n-    sock = getattr(conn, \"sock\", False)\n+    sock = getattr(conn, \"sock\", None)\n     if sock is None:  # Connection already closed (such as by httplib).\n         return True\n     # Returns True if readable, which here means it's been dropped\n", "issue": "is_connection_dropped checks against None but uses False as default value for getattr\nI happened to read this line and the code looks fishy. I did not otherwise verify the potential bug.\r\n\r\nSee implementation of `is_connection_dropped(conn: socket.socket) -> bool`:\r\n\r\nhttps://github.com/urllib3/urllib3/blob/287052a16a59bcaba5772387de36fa9a49eb8378/src/urllib3/util/connection.py#L19-L23\r\n\r\nIf there is no property `sock` on `conn`, then we will call `wait_for_read(False, timeout=0.0)`, which e.g. may end up putting the `False` into the iterable passed to `select`.\r\n\r\nSince this seemed to never have caused problems, the `sock = getattr(conn, \"sock\", False)` can probably be replaced with just `sock = conn.sock`.\r\n\r\nAlternatives would be to replace the default (last argument of `getattr`) of `False` with `None` or replace the `if sock is None` with `if not sock`.\n", "before_files": [{"content": "import socket\nfrom typing import List, Optional, Tuple, Union\n\nfrom urllib3.exceptions import LocationParseError\n\nfrom .wait import wait_for_read\n\nSOCKET_GLOBAL_DEFAULT_TIMEOUT = socket._GLOBAL_DEFAULT_TIMEOUT  # type: ignore\nSocketOptions = List[Tuple[int, int, Union[int, bytes]]]\n\n\ndef is_connection_dropped(conn: socket.socket) -> bool:  # Platform-specific\n    \"\"\"\n    Returns True if the connection is dropped and should be closed.\n\n    :param conn:\n        :class:`http.client.HTTPConnection` object.\n    \"\"\"\n    sock = getattr(conn, \"sock\", False)\n    if sock is None:  # Connection already closed (such as by httplib).\n        return True\n    # Returns True if readable, which here means it's been dropped\n    return wait_for_read(sock, timeout=0.0)\n\n\n# This function is copied from socket.py in the Python 2.7 standard\n# library test suite. Added to its signature is only `socket_options`.\n# One additional modification is that we avoid binding to IPv6 servers\n# discovered in DNS if the system doesn't have IPv6 functionality.\ndef create_connection(\n    address: Tuple[str, int],\n    timeout: Optional[float] = SOCKET_GLOBAL_DEFAULT_TIMEOUT,\n    source_address: Optional[Tuple[str, int]] = None,\n    socket_options: Optional[SocketOptions] = None,\n) -> socket.socket:\n    \"\"\"Connect to *address* and return the socket object.\n\n    Convenience function.  Connect to *address* (a 2-tuple ``(host,\n    port)``) and return the socket object.  Passing the optional\n    *timeout* parameter will set the timeout on the socket instance\n    before attempting to connect.  If no *timeout* is supplied, the\n    global default timeout setting returned by :func:`socket.getdefaulttimeout`\n    is used.  If *source_address* is set it must be a tuple of (host, port)\n    for the socket to bind as a source address before making the connection.\n    An host of '' or port 0 tells the OS to use the default.\n    \"\"\"\n\n    host, port = address\n    if host.startswith(\"[\"):\n        host = host.strip(\"[]\")\n    err = None\n\n    # Using the value from allowed_gai_family() in the context of getaddrinfo lets\n    # us select whether to work with IPv4 DNS records, IPv6 records, or both.\n    # The original create_connection function always returns all records.\n    family = allowed_gai_family()\n\n    try:\n        host.encode(\"idna\")\n    except UnicodeError:\n        raise LocationParseError(f\"'{host}', label empty or too long\") from None\n\n    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\n        af, socktype, proto, canonname, sa = res\n        sock = None\n        try:\n            sock = socket.socket(af, socktype, proto)\n\n            # If provided, set socket level options before connecting.\n            _set_socket_options(sock, socket_options)\n\n            if timeout is not SOCKET_GLOBAL_DEFAULT_TIMEOUT:\n                sock.settimeout(timeout)\n            if source_address:\n                sock.bind(source_address)\n            sock.connect(sa)\n            return sock\n\n        except OSError as e:\n            err = e\n            if sock is not None:\n                sock.close()\n                sock = None\n\n    if err is not None:\n        raise err\n\n    raise OSError(\"getaddrinfo returns an empty list\")\n\n\ndef _set_socket_options(sock: socket.socket, options: Optional[SocketOptions]) -> None:\n    if options is None:\n        return\n\n    for opt in options:\n        sock.setsockopt(*opt)\n\n\ndef allowed_gai_family() -> socket.AddressFamily:\n    \"\"\"This function is designed to work in the context of\n    getaddrinfo, where family=socket.AF_UNSPEC is the default and\n    will perform a DNS search for both IPv6 and IPv4 records.\"\"\"\n\n    family = socket.AF_INET\n    if HAS_IPV6:\n        family = socket.AF_UNSPEC\n    return family\n\n\ndef _has_ipv6(host: str) -> bool:\n    \"\"\" Returns True if the system can bind an IPv6 address. \"\"\"\n    sock = None\n    has_ipv6 = False\n\n    if socket.has_ipv6:\n        # has_ipv6 returns true if cPython was compiled with IPv6 support.\n        # It does not tell us if the system has IPv6 support enabled. To\n        # determine that we must bind to an IPv6 address.\n        # https://github.com/urllib3/urllib3/pull/611\n        # https://bugs.python.org/issue658327\n        try:\n            sock = socket.socket(socket.AF_INET6)\n            sock.bind((host, 0))\n            has_ipv6 = True\n        except Exception:\n            pass\n\n    if sock:\n        sock.close()\n    return has_ipv6\n\n\nHAS_IPV6 = _has_ipv6(\"::1\")\n", "path": "src/urllib3/util/connection.py"}], "after_files": [{"content": "import socket\nfrom typing import List, Optional, Tuple, Union\n\nfrom urllib3.exceptions import LocationParseError\n\nfrom .wait import wait_for_read\n\nSOCKET_GLOBAL_DEFAULT_TIMEOUT = socket._GLOBAL_DEFAULT_TIMEOUT  # type: ignore\nSocketOptions = List[Tuple[int, int, Union[int, bytes]]]\n\n\ndef is_connection_dropped(conn: socket.socket) -> bool:  # Platform-specific\n    \"\"\"\n    Returns True if the connection is dropped and should be closed.\n\n    :param conn:\n        :class:`http.client.HTTPConnection` object.\n    \"\"\"\n    sock = getattr(conn, \"sock\", None)\n    if sock is None:  # Connection already closed (such as by httplib).\n        return True\n    # Returns True if readable, which here means it's been dropped\n    return wait_for_read(sock, timeout=0.0)\n\n\n# This function is copied from socket.py in the Python 2.7 standard\n# library test suite. Added to its signature is only `socket_options`.\n# One additional modification is that we avoid binding to IPv6 servers\n# discovered in DNS if the system doesn't have IPv6 functionality.\ndef create_connection(\n    address: Tuple[str, int],\n    timeout: Optional[float] = SOCKET_GLOBAL_DEFAULT_TIMEOUT,\n    source_address: Optional[Tuple[str, int]] = None,\n    socket_options: Optional[SocketOptions] = None,\n) -> socket.socket:\n    \"\"\"Connect to *address* and return the socket object.\n\n    Convenience function.  Connect to *address* (a 2-tuple ``(host,\n    port)``) and return the socket object.  Passing the optional\n    *timeout* parameter will set the timeout on the socket instance\n    before attempting to connect.  If no *timeout* is supplied, the\n    global default timeout setting returned by :func:`socket.getdefaulttimeout`\n    is used.  If *source_address* is set it must be a tuple of (host, port)\n    for the socket to bind as a source address before making the connection.\n    An host of '' or port 0 tells the OS to use the default.\n    \"\"\"\n\n    host, port = address\n    if host.startswith(\"[\"):\n        host = host.strip(\"[]\")\n    err = None\n\n    # Using the value from allowed_gai_family() in the context of getaddrinfo lets\n    # us select whether to work with IPv4 DNS records, IPv6 records, or both.\n    # The original create_connection function always returns all records.\n    family = allowed_gai_family()\n\n    try:\n        host.encode(\"idna\")\n    except UnicodeError:\n        raise LocationParseError(f\"'{host}', label empty or too long\") from None\n\n    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):\n        af, socktype, proto, canonname, sa = res\n        sock = None\n        try:\n            sock = socket.socket(af, socktype, proto)\n\n            # If provided, set socket level options before connecting.\n            _set_socket_options(sock, socket_options)\n\n            if timeout is not SOCKET_GLOBAL_DEFAULT_TIMEOUT:\n                sock.settimeout(timeout)\n            if source_address:\n                sock.bind(source_address)\n            sock.connect(sa)\n            return sock\n\n        except OSError as e:\n            err = e\n            if sock is not None:\n                sock.close()\n                sock = None\n\n    if err is not None:\n        raise err\n\n    raise OSError(\"getaddrinfo returns an empty list\")\n\n\ndef _set_socket_options(sock: socket.socket, options: Optional[SocketOptions]) -> None:\n    if options is None:\n        return\n\n    for opt in options:\n        sock.setsockopt(*opt)\n\n\ndef allowed_gai_family() -> socket.AddressFamily:\n    \"\"\"This function is designed to work in the context of\n    getaddrinfo, where family=socket.AF_UNSPEC is the default and\n    will perform a DNS search for both IPv6 and IPv4 records.\"\"\"\n\n    family = socket.AF_INET\n    if HAS_IPV6:\n        family = socket.AF_UNSPEC\n    return family\n\n\ndef _has_ipv6(host: str) -> bool:\n    \"\"\" Returns True if the system can bind an IPv6 address. \"\"\"\n    sock = None\n    has_ipv6 = False\n\n    if socket.has_ipv6:\n        # has_ipv6 returns true if cPython was compiled with IPv6 support.\n        # It does not tell us if the system has IPv6 support enabled. To\n        # determine that we must bind to an IPv6 address.\n        # https://github.com/urllib3/urllib3/pull/611\n        # https://bugs.python.org/issue658327\n        try:\n            sock = socket.socket(socket.AF_INET6)\n            sock.bind((host, 0))\n            has_ipv6 = True\n        except Exception:\n            pass\n\n    if sock:\n        sock.close()\n    return has_ipv6\n\n\nHAS_IPV6 = _has_ipv6(\"::1\")\n", "path": "src/urllib3/util/connection.py"}]}