Fix #2096: harden NamedLocksTrackingFileManagerTest against CI load (#2098)

## Summary

- Increase per-operation lock timeout from 5s → 30s in `NamedLocksTrackingFileManagerTest`
- Add proper `FileLockNamedLockFactory.shutdown()` in `@AfterEach` to close idle channels and lock files

## Root cause analysis

The test runs 4 threads × 1000 iterations of concurrent `read(shared)` + `update(exclusive)` against the same file, exercising the full `FileLockNamedLock` contention path. Each exclusive lock attempt retries with a 100ms sleep between attempts.

The 5-second timeout was **already bumped from 1s → 5s** in [194128ae](https://github.com/apache/maven-resolver/commit/194128ae) ("Seems timeout of 1s is not enough?"). Recent performance optimizations (#1937) changed the lock acquisition timing characteristics:

1. The **lock-free fast path** in `NamedLockFactorySupport.getLockAndRefTrack()` makes `getLock()` much faster, allowing threads to re-acquire locks more rapidly and increasing file lock contention
2. The **idle channel pool** in `FileLockNamedLockFactory` (from the FD leak fix) adds a small amount of work inside `locks.compute()`, marginally extending the time the ConcurrentHashMap bucket lock is held

Neither change introduces a concurrency bug — the channel management is correctly serialized by `locks.compute()` bucket locks, and the `tryIncRef` CAS sentinel correctly prevents revival of destroyed holders. However, on loaded CI machines, the changed timing profile can push borderline operations past the 5s threshold.

The factory was also never shut down after tests, leaking idle `FileChannel` instances.
1 file changed
tree: 1da9333fe27e78928c07712b51f035eb01707534
  1. .github/
  2. .mvn/
  3. maven-resolver-api/
  4. maven-resolver-connector-basic/
  5. maven-resolver-demos/
  6. maven-resolver-generator-gnupg/
  7. maven-resolver-generator-sigstore/
  8. maven-resolver-impl/
  9. maven-resolver-named-locks/
  10. maven-resolver-named-locks-hazelcast/
  11. maven-resolver-named-locks-ipc/
  12. maven-resolver-named-locks-redisson/
  13. maven-resolver-spi/
  14. maven-resolver-supplier-mvn3/
  15. maven-resolver-supplier-mvn4/
  16. maven-resolver-test-http/
  17. maven-resolver-test-util/
  18. maven-resolver-tools/
  19. maven-resolver-transport-apache/
  20. maven-resolver-transport-classpath/
  21. maven-resolver-transport-file/
  22. maven-resolver-transport-jdk-parent/
  23. maven-resolver-transport-jetty/
  24. maven-resolver-transport-minio/
  25. maven-resolver-transport-url/
  26. maven-resolver-transport-wagon/
  27. maven-resolver-util/
  28. src/
  29. .asf.yaml
  30. .git-blame-ignore-revs
  31. .gitignore
  32. AGENTS.md
  33. class-overview.svg
  34. Jenkinsfile
  35. LICENSE
  36. pom.xml
  37. README.md
  38. SECURITY.md
README.md

Contributing to Apache Maven Artifact Resolver

Apache License, Version 2.0, January 2004 Maven Central Reproducible Builds Jenkins Status Jenkins tests

You have found a bug, or you have an idea for a cool new feature? Contributing code is a great way to give something back to the open source community. Before you dig right into the code, there are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.

Getting Started

  • Make sure you have a GitHub account.
  • If you‘re planning to implement a new feature, it makes sense to discuss your changes on the dev list first. This way you can make sure you’re not wasting your time on something that isn‘t considered to be in Apache Maven’s scope.
  • Submit a ticket for your issue, assuming one does not already exist.
    • Clearly describe the issue, including steps to reproduce when it is a bug.
    • Make sure you fill in the earliest version that you know has the issue.
  • Fork the repository on GitHub.

Making and Submitting Changes

We accept Pull Requests via GitHub. The developer mailing list is the main channel of communication for contributors. There are some guidelines which will make applying PRs easier for us:

  • Create a topic branch from where you want to base your work (this is usually the master branch). Push your changes to a topic branch in your fork of the repository.
  • Make commits of logical units.
  • Respect the original code style: by using the same codestyle, patches should only highlight the actual difference, not being disturbed by any formatting issues:
    • Only use spaces for indentation.
    • Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted, create a separate PR for this change.
    • Check for unnecessary whitespace with git diff --check before committing.
  • Make sure you have added the necessary tests (JUnit/IT) for your changes.
  • Run all the tests with mvn -Prun-its verify to assure nothing else was accidentally broken.
  • Submit a pull request to the repository in the Apache organization.

If you plan to contribute on a regular basis, please consider filing a contributor license agreement.

Additional Resources