diff --git a/.github/workflows/jvm_tests.yml b/.github/workflows/jvm_tests.yml index 9ef314ca5..640e41bdb 100644 --- a/.github/workflows/jvm_tests.yml +++ b/.github/workflows/jvm_tests.yml @@ -16,23 +16,20 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-latest, ubuntu-latest, macos-11] + os: [windows-latest, ubuntu-latest, macos-13] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - - uses: mamba-org/setup-micromamba@422500192359a097648154e8db4e39bdb6c6eed7 # v1.8.1 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - micromamba-version: '1.5.6-0' - environment-name: jvm_tests - create-args: >- - python=3.10 - awscli - cache-downloads: true - cache-environment: true - init-shell: bash powershell + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: jvm_tests + environment-file: tests/ci_build/conda_env/jvm_tests.yml + use-mamba: true - name: Cache Maven packages uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 @@ -61,7 +58,7 @@ jobs: id: extract_branch if: | (github.ref == 'refs/heads/master' || contains(github.ref, 'refs/heads/release_')) && - (matrix.os == 'windows-latest' || matrix.os == 'macos-11') + (matrix.os == 'windows-latest' || matrix.os == 'macos-13') - name: Publish artifact xgboost4j.dll to S3 run: | @@ -85,7 +82,7 @@ jobs: python -m awscli s3 cp libxgboost4j_${{ github.sha }}.dylib s3://xgboost-nightly-builds/${{ steps.extract_branch.outputs.branch }}/libxgboost4j/ --acl public-read --region us-west-2 if: | (github.ref == 'refs/heads/master' || contains(github.ref, 'refs/heads/release_')) && - matrix.os == 'macos-11' + matrix.os == 'macos-13' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_IAM_S3_UPLOADER }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_IAM_S3_UPLOADER }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4755f9aaa..4be35e9de 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-11] + os: [macos-12] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: @@ -33,7 +33,7 @@ jobs: run: | mkdir build cd build - cmake .. -DGOOGLE_TEST=ON -DUSE_OPENMP=ON -DUSE_DMLC_GTEST=ON -GNinja -DBUILD_DEPRECATED_CLI=ON + cmake .. -DGOOGLE_TEST=ON -DUSE_OPENMP=ON -DUSE_DMLC_GTEST=ON -GNinja -DBUILD_DEPRECATED_CLI=ON -DUSE_SANITIZER=ON -DENABLED_SANITIZERS=address -DCMAKE_BUILD_TYPE=RelWithDebInfo ninja -v - name: Run gtest binary run: | @@ -79,13 +79,13 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - - uses: mamba-org/provision-with-micromamba@3c96c0c27676490c63c18bc81f5c51895ac3e0e6 # v16 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - cache-downloads: true - cache-env: true - environment-name: linux_sycl_test + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: linux_sycl_test environment-file: tests/ci_build/conda_env/linux_sycl_test.yml - + use-mamba: true - name: Display Conda env run: | conda info @@ -121,12 +121,13 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - - uses: mamba-org/provision-with-micromamba@3c96c0c27676490c63c18bc81f5c51895ac3e0e6 # v16 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - cache-downloads: true - cache-env: true - environment-name: cpp_test + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: cpp_test environment-file: tests/ci_build/conda_env/cpp_test.yml + use-mamba: true - name: Display Conda env run: | conda info diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index f0cad6382..e3b60f12c 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -24,12 +24,13 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - - uses: mamba-org/provision-with-micromamba@3c96c0c27676490c63c18bc81f5c51895ac3e0e6 # v16 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - cache-downloads: true - cache-env: true - environment-name: python_lint + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: python_lint environment-file: tests/ci_build/conda_env/python_lint.yml + use-mamba: true - name: Display Conda env run: | conda info @@ -55,12 +56,13 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - - uses: mamba-org/provision-with-micromamba@3c96c0c27676490c63c18bc81f5c51895ac3e0e6 # v16 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - cache-downloads: true - cache-env: true - environment-name: sdist_test + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: sdist_test environment-file: tests/ci_build/conda_env/sdist_test.yml + use-mamba: true - name: Display Conda env run: | conda info @@ -81,14 +83,14 @@ jobs: name: Test installing XGBoost Python source package on ${{ matrix.os }} strategy: matrix: - os: [macos-11, windows-latest] + os: [macos-13, windows-latest] python-version: ["3.8"] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - name: Install osx system dependencies - if: matrix.os == 'macos-11' + if: matrix.os == 'macos-13' run: | brew install ninja libomp - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 @@ -119,19 +121,20 @@ jobs: strategy: matrix: config: - - {os: macos-11} + - {os: macos-13} steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - - uses: mamba-org/provision-with-micromamba@3c96c0c27676490c63c18bc81f5c51895ac3e0e6 # v16 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - cache-downloads: true - cache-env: true - environment-name: macos_test + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: macos_cpu_test environment-file: tests/ci_build/conda_env/macos_cpu_test.yml + use-mamba: true - name: Display Conda env run: | @@ -222,12 +225,13 @@ jobs: with: submodules: 'true' - - uses: mamba-org/provision-with-micromamba@3c96c0c27676490c63c18bc81f5c51895ac3e0e6 # v16 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - cache-downloads: true - cache-env: true - environment-name: linux_cpu_test + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: linux_cpu_test environment-file: tests/ci_build/conda_env/linux_cpu_test.yml + use-mamba: true - name: Display Conda env run: | @@ -274,12 +278,13 @@ jobs: with: submodules: 'true' - - uses: mamba-org/provision-with-micromamba@3c96c0c27676490c63c18bc81f5c51895ac3e0e6 # v16 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: - cache-downloads: true - cache-env: true - environment-name: linux_sycl_test + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: linux_sycl_test environment-file: tests/ci_build/conda_env/linux_sycl_test.yml + use-mamba: true - name: Display Conda env run: | diff --git a/.github/workflows/python_wheels.yml b/.github/workflows/python_wheels.yml index 090b1f830..e9521d447 100644 --- a/.github/workflows/python_wheels.yml +++ b/.github/workflows/python_wheels.yml @@ -28,7 +28,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: submodules: 'true' - - uses: conda-incubator/setup-miniconda@v3.0.4 + - uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4 with: miniforge-variant: Mambaforge miniforge-version: latest diff --git a/src/collective/tracker.cc b/src/collective/tracker.cc index f4c07c5d1..c8776f294 100644 --- a/src/collective/tracker.cc +++ b/src/collective/tracker.cc @@ -19,6 +19,7 @@ #include // for sort #include // for seconds, ms #include // for int32_t +#include // for unique_ptr #include // for string #include // for move, forward @@ -376,20 +377,51 @@ Result RabitTracker::Bootstrap(std::vector* p_workers) { if (!rc.OK()) { return rc; } - auto host = gethostbyname(out->c_str()); - // get ip address from host - std::string ip; - rc = INetNToP(host, &ip); - if (!rc.OK()) { - return rc; + addrinfo hints; + addrinfo* servinfo; + + std::memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE; + + std::int32_t errc{0}; + std::unique_ptr> guard{&servinfo, [](addrinfo** ptr) { + freeaddrinfo(*ptr); + }}; + if ((errc = getaddrinfo(nullptr, "0", &hints, &servinfo)) != 0) { + return Fail("Failed to get address info:" + std::string{gai_strerror(errc)}); } - if (!(ip.size() >= 4 && ip.substr(0, 4) == "127.")) { - // return if this is a public IP address. - // not entirely accurate, we have other reserved IPs - *out = ip; - return Success(); + // https://beej.us/guide/bgnet/html/#getaddrinfoprepare-to-launch + std::vector addresses; + for (addrinfo* p = servinfo; p != nullptr; p = p->ai_next) { + // Get the pointer to the address itself, different fields in IPv4 and IPv6: + if (p->ai_family == AF_INET) { // IPv4 + struct sockaddr_in* ipv4 = reinterpret_cast(p->ai_addr); + addresses.emplace_back(SockAddrV4{*ipv4}); + auto ip = addresses.back().V4().Addr(); + // Priortize V4. + // Return if this is a public IP address. Not accurate, we have other reserved IPs + if (ip.size() > 4 && ip.substr(0, 4) != "127." && ip != SockAddrV4::InaddrAny().Addr()) { + *out = ip; + return Success(); + } + } else { + struct sockaddr_in6* ipv6 = reinterpret_cast(p->ai_addr); + addresses.emplace_back(SockAddrV6{*ipv6}); + } + } + // If not v4 address is found, we try v6 + for (auto const& addr : addresses) { + if (addr.IsV6()) { + auto ip = addr.V6().Addr(); + if (ip != SockAddrV6::InaddrAny().Addr() && ip != SockAddrV6::Loopback().Addr()) { + *out = ip; + return Success(); + } + } } // Create an UDP socket to prob the public IP address, it's fine even if it's @@ -413,7 +445,7 @@ Result RabitTracker::Bootstrap(std::vector* p_workers) { if (getsockname(sock, reinterpret_cast(&addr), &len) == -1) { return Fail("Failed to get sock name."); } - ip = inet_ntoa(addr.sin_addr); + std::string ip = inet_ntoa(addr.sin_addr); err = system::CloseSocket(sock); if (err != 0) { diff --git a/tests/ci_build/conda_env/jvm_tests.yml b/tests/ci_build/conda_env/jvm_tests.yml new file mode 100644 index 000000000..56e11dff2 --- /dev/null +++ b/tests/ci_build/conda_env/jvm_tests.yml @@ -0,0 +1,6 @@ +name: jvm_tests +channels: +- conda-forge +dependencies: +- python=3.10 +- awscli