Visitar URL original
RandomAccessVectorValues::threadLocalSupplier leaks objects · Issue #635 · datastax/jvector · GitHub
Skip to content

RandomAccessVectorValues::threadLocalSupplier leaks objects #635

Open

Description

@michaeljmarshall

The current implementations:

    default Supplier<RandomAccessVectorValues> threadLocalSupplier() {
        if (!isValueShared()) {
            return () -> this;
        }

        if (this instanceof AutoCloseable) {
            LOG.warning("RAVV is shared and implements AutoCloseable; threadLocalSupplier() may lead to leaks");
        }
        var tl = ExplicitThreadLocal.withInitial(this::copy);
        return tl::get;
    }

I'd like to see if we can find an elegant solution that allows us to remove the warning log and properly close resources when they implement AutoCloseable.

Activity

  1. ikaitist commented on Aug 24, 2026

    @ikaitist

    I would like to work on this. Root cause: the default threadLocalSupplier() creates per-thread copies via ExplicitThreadLocal and never closes them (the code itself warns when the RAVV is AutoCloseable). Consumers holding the supplier across pooled threads keep those copies and their backing memory alive indefinitely.

    I see two directions and would welcome a maintainer call:

    1. Track created copies in the supplier and dispose them through a lifecycle hook (e.g. the RAVV close() path or a new supplier method).
    2. Make the supplier per-thread copies weakly held and re-created when collected; AutoCloseable copies would still need explicit closing.

    Happy to implement whichever direction you prefer, with tests.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions