Skip to content

BasicRepositoryConnector.get(...) immediately fails on first exception of a single remote repository #2366

In progress

Description

@kwin

Affected version

Maven 3.9.16 (but probably also 2.x resolver)

Bug description

I use multiple remote repositories.
Checking the highest version and then resolving (via API from https://github.com/bndtools/bnd/blob/0ca31d7acb96158049b56bc1749f4956ce5d1517/maven-plugins/bnd-baseline-maven-plugin/src/main/java/aQute/bnd/maven/baseline/plugin/BaselineMojo.java#L203) leads to the following logs

[INFO] Determining the baseline version for be.orbinson.aem:aem-dictionary-translator.core:jar:(,1.7.1-SNAPSHOT) using repositories [sonatype-central-portal (https://repo.maven.apache.org/maven2, default, releases+snapshots), central (https://repo.maven.apache.org/maven2, default, releases), nexus-netcentric (https://repo.int.netcentric.biz/nexus/content/groups/netcentric/, default, releases+snapshots)]
[INFO] Created Njord artifact store aem-dictionary-translator-00002 for remote repository sonatype-central-portal (https://repo.maven.apache.org/maven2, default, releases+snapshots)
INFO] Downloading from aem-dictionary-translator-00002: file:///Users/715508/.njord/aem-dictionary-translator-00002/be/orbinson/aem/aem-dictionary-translator.core/maven-metadata.xml
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/be/orbinson/aem/aem-dictionary-translator.core/maven-metadata.xml
[INFO] Downloading from nexus-netcentric: https://repo.int.netcentric.biz/nexus/content/groups/netcentric/be/orbinson/aem/aem-dictionary-translator.core/maven-metadata.xml
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/be/orbinson/aem/aem-dictionary-translator.core/maven-metadata.xml (1.2 kB at 5.8 kB/s)
[WARNING] Could not transfer metadata be.orbinson.aem:aem-dictionary-translator.core/maven-metadata.xml from/to nexus-netcentric (https://repo.int.netcentric.biz/nexus/content/groups/netcentric/): repo.int.netcentric.biz: nodename nor servname provided, or not known
[INFO] The baseline version was found to be 1.7.0
[INFO] Downloading from aem-dictionary-translator-00002: file:///Users/715508/.njord/aem-dictionary-translator-00002/be/orbinson/aem/aem-dictionary-translator.core/1.7.0/aem-dictionary-translator.core-1.7.0.jar
[INFO] Downloading from nexus-netcentric: https://repo.int.netcentric.biz/nexus/content/groups/netcentric/be/orbinson/aem/aem-dictionary-translator.core/1.7.0/aem-dictionary-translator.core-1.7.0.jar
...
[ERROR] Failed to execute goal biz.aQute.bnd:bnd-baseline-maven-plugin:7.4.0:baseline (baseline) on project ... Unable to locate a previous version of the artifact

This seems to be a race condition as depending on which remote repository responds first determines the outcome. Although the artifact is available on central (https://repo.maven.apache.org/maven2/be/orbinson/aem/aem-dictionary-translator.core/1.7.0/aem-dictionary-translator.core-1.7.0.jar) it is not in in nexus-netcentric. Resolving from the latter leads to a org.eclipse.aether.RepositoryException (wrapping a java.net.UnknownHostException).

The culprit is probably within

which tries to download in parallel from all remote repos.
Once a single thread hits an exception this leads to propagating the exception to the caller, without waiting for any of the other remote repos.

In my case the exception is a UnknownHostException (which is unfortunately swallowed in https://github.com/bndtools/bnd/blob/0ca31d7acb96158049b56bc1749f4956ce5d1517/maven-plugins/bnd-baseline-maven-plugin/src/main/java/aQute/bnd/maven/baseline/plugin/BaselineMojo.java#L137) and therefore not visible in the logs above.

I would argue the outcome should not depend on the fastest responding remote repo. If one fails with an exception the other remote repos should still be tried.

Activity

  1. added
    bug
    on Nov 27, 2026
  2. kwin commented on Nov 28, 2026

    @kwin
    MemberAuthor

    According to GPT 6 Luna:

    Parallel downloads are implemented in the basic connector, per remote repository:

    BasicRepositoryConnector.getExecutor creates a downstream executor when there’s more than one download task. get submits download tasks to it (line 270) and waits for them to finish.
    The limit is aether.connector.basic.downstreamThreads, default 5; it can also be set per repo ID. See BasicRepositoryConnectorConfigurationKeys and its use in the connector constructor (lines 166–168).
    However, DefaultArtifactResolver iterates repository groups and calls performDownloads sequentially. So this parallelism is for multiple files from one repository, not downloading the same artifact from multiple remote repositories at once.

    However I am wondering why the order for downloading metadata differs from the order for downloading artifacts and why the log still exposes multiple remote repos being requested in parallel...

  3. cstamas commented on Nov 28, 2026

    @cstamas
    Member

    This is a bit wrong: connector instances are created for one remote repository. Transporter instance is created by connector, hence are also per remote repository. So each connector "talks" to one remote repository via gotten transporter.

    Hence, I don't understand "depending on which remote repository responds first determines the outcome" sentence, as connector talks to one single remote repository.

  4. cstamas commented on Nov 28, 2026

    @cstamas
    Member

    I don't think this is a race, and BasicRepositoryConnector.get does not stop at the first failure. Each transfer's exception is caught in TaskRunner.run() and stored on that transfer, and errorForwarder.await() waits for all tasks to finish. In any case, a connector only ever talks to one remote repository.

    What I think actually happens:

    1. Metadata is resolved for each repository separately, and in parallel (DefaultMetadataResolver, one ResolveTask per repository). That's why the log shows three metadata requests at the same time, and why 1.7.0 is found in central.
    2. Artifacts are resolved one repository group at a time. Repositories are put into the same ResolutionGroup when their URL, content type and repository-manager flag match. The repository ID is ignored:
      boolean matches(RemoteRepository repo) {
      return repository.getUrl().equals(repo.getUrl())
      && repository.getContentType().equals(repo.getContentType())
      && repository.isRepositoryManager() == repo.isRepositoryManager();
      }

      sonatype-central-portal and central both have the URL https://repo.maven.apache.org/maven2. So central is folded into the group of sonatype-central-portal, which comes first in the list, and that group downloads through sonatype-central-portal.
    3. Njord takes over sonatype-central-portal and serves it from its local store (file:///…/.njord/aem-dictionary-translator-00002). The jar is not in that store, so it's "not found". central is never contacted for the jar, which matches the log: there is no "Downloading from central" line for the .jar.
    4. The next group is nexus-netcentric, which fails with UnknownHostException. The artifact ends up missing, and BaselineMojo swallows the RepositoryException and reports "Unable to locate a previous version of the artifact".

    So this is an interaction between the resolver's grouping by URL and Njord. The grouping assumes that the same URL means the same content. Njord breaks that assumption by redirecting by repository ID while the URL stays the same. Without Njord, the merged group would fetch from the real Central and succeed.

    To confirm: run the same build without Njord, or remove the duplicate sonatype-central-portal entry from the repository list. The jar should then resolve from central.

    Possible fixes:

    • Njord rewrites the URL of the repository it redirects, so it no longer matches central; or
    • ResolutionGroup.matches() also compares repository IDs, but that loses the dedupe this grouping exists for.
  5. kwin commented on Nov 28, 2026

    @kwin
    MemberAuthor

    @cstamas Thanks a lot for those insights, however I am wondering why always the artifact is requested/downloaded from all group remote repos (in

    ). Once the first one returns a non error response the other downloads (for the same artifact) become irrelevant, isn't it?

    This is a pretty bad edge case, because bnd-resolver-maven-plugin incorrectly considers the distribution repository for resolving (bndtools/bnd#6945), therefore sonatype-central-portal ends up in the remote repos in the first place. Looks like maveniverse/njord#214 should solve this.

  6. cstamas commented on Nov 28, 2026

    @cstamas
    Member

    Why on earth bnd does this? I think same happens in CycloneDX...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions