python/cpython · error · ValueError

BUILD_GNU_TYPE is not defined

Error message

BUILD_GNU_TYPE is not defined

What it means

_ensure_fd_no_transport() raises RuntimeError when the fd being registered is already owned by a live (not closing) transport in this loop. The loop forbids two independent watchers on one fd because the transport would receive the events. It is a duplicate-registration guard, not a resource leak error.

Source

Thrown at Lib/_aix_support.py:91

    Again, the builddate of an AIX release is associated with bos.rte.
    AIX ABI compatibility is described  as guaranteed at: https://www.ibm.com/\
    support/knowledgecenter/en/ssw_aix_72/install/binary_compatability.html

    For pep425 purposes the AIX platform tag becomes:
    "aix-{:1x}{:1d}{:02d}-{:04d}-{}".format(v, r, tl, builddate, bitsize)
    e.g., "aix-6107-1415-32" for AIX 6.1 TL7 bd 1415, 32-bit
    and, "aix-6107-1415-64" for AIX 6.1 TL7 bd 1415, 64-bit
    """
    vrmf, bd = _aix_bos_rte()
    return _aix_tag(_aix_vrtl(vrmf), bd)


# extract vrtl from the BUILD_GNU_TYPE as an int
def _aix_bgt():
    # type: () -> List[int]
    gnu_type = sysconfig.get_config_var("BUILD_GNU_TYPE")
    if not gnu_type:
        raise ValueError("BUILD_GNU_TYPE is not defined")
    return _aix_vrtl(vrmf=gnu_type)


def aix_buildtag():
    # type: () -> str
    """
    Return the platform_tag of the system Python was built on.
    """
    # AIX_BUILDDATE is defined by configure with:
    # lslpp -Lcq bos.rte | awk -F:  '{ print $NF }'
    build_date = sysconfig.get_config_var("AIX_BUILDDATE")
    try:
        build_date = int(build_date)
    except (ValueError, TypeError):
        raise ValueError(f"AIX_BUILDDATE is not defined or invalid: "
                         f"{build_date!r}")
    return _aix_tag(_aix_bgt(), build_date)

View on GitHub (pinned to bc6749cc3b)

Solutions

  1. Pick one API per socket: either the transport/protocol layer or the raw sock_*/add_reader layer, never both
  2. Detach the fd from the transport first (tr.get_extra_info('socket').detach()) if you truly must take over, accepting transport teardown
  3. Reuse the existing transport's methods (tr.write, protocol callbacks) instead of watching its fd
  4. For takeover scenarios, abort the old transport (tr.abort()) before registering the fd yourself

Example fix

# before
tr, _ = await loop.create_connection(Proto, host, port)
loop.add_reader(sock_from_tr, cb)  # fd owned by transport -> RuntimeError
# after
tr, proto = await loop.create_connection(Proto, host, port)
# use the transport/protocol surface instead of add_reader on its fd
tr.write(b'ping')  # responses arrive via proto.data_received
Defensive patterns

Strategy: validation

Validate before calling

def assert_fd_free(loop, sock):
    fd = sock.fileno()
    tr = loop._transports.get(fd)          # same map the loop checks
    if tr is not None and not tr.is_closing():
        raise RuntimeError(f'fd {fd} owned by {tr!r}; use the transport instead')

Try / catch

try:
    loop.add_reader(sock, cb)
except RuntimeError as e:
    if 'is used by transport' in str(e):
        tr = loop._transports.get(sock.fileno())
        tr.abort()                      # release ownership, then re-register
        loop.add_reader(sock, cb)
    else:
        raise

Prevention

When it happens

Trigger: Calling loop.add_reader(sock)/add_writer or sock_* on a socket already attached to a transport created by create_connection/create_datagram_endpoint; passing the same socket to two create_*_endpoint calls; using a transport's socket (tr.get_extra_info('socket')) with raw loop APIs while the transport lives.

Common situations: Peeking at a connection's socket to do zero-copy reads or sendfile while the transport still polls it; writing custom protocols and mixing transport-level and sock-level APIs on the same fd; workarounds copied from selector-era code that manipulated fds directly; double-starting a server on the same listening socket.

Related errors


AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14). Data as JSON: /api/errors/0b7bcf38d3da8c86. Report an issue: GitHub.