Skip to content

LocalDocumentType.setAliases does a check-then-put on the shared type map with no write lock, the two holes just closed in rename(), createProperty and dropProperty #8064

Closed

Description

@ruispereira

Summary

LocalDocumentType.setAliases mutates the schema's shared type map with a check-then-act sequence and no write lock, which is the arrangement the neighbouring mutators were just converted away from.

Two separate holes in the same method:

  1. Check-then-put. It refuses an alias already used by another type by calling schema.existsType(alias), then, several statements later, puts the alias into schema.typeMap(). Nothing holds the map between the two, so two concurrent ALTER TYPE ... ALIASES on different types can both pass the check and the second put silently wins.
  2. Unconditional deregistration. It removes every previous alias from schema.typeMap() before installing the new set. A concurrent reader resolving one of those names sees it disappear even when the new set still contains it, because the remove loop and the put loop are separate passes over a shared map.

The class's own comment on the field already claims the protection this method does not take.

Where (HEAD 28b71e3)

engine/src/main/java/com/arcadedb/schema/LocalDocumentType.java:470-492:

  public LocalDocumentType setAliases(final Set<String> aliases) {
    checkForSchemaMutation();
    final Set<String> newAliases = new HashSet<>(aliases);
    newAliases.removeAll(this.aliases);
    for (String alias : newAliases) {
      if (schema.existsType(alias))
        throw new SchemaException("Cannot set alias '" + alias + "' for type '" + name + "' because it is already used by type '"
            + schema.getType(alias).getName() + "'");
    }

    // DEREGISTER ALL PREVIOUS ALIASES
    for (String alias : this.aliases)
      schema.typeMap().remove(alias);

    for (String alias : aliases)
      schema.typeMap().put(alias, this);

checkForSchemaMutation() is a precondition check, not a lock. Compare the mutators that were converted: createProperty (:701) and dropProperty (:859) both run every check AND the mutation inside a single recordFileChanges(...) callback, and their javadocs (:678-683, :841-845) state why. rename() (:244) does the same and additionally uses a write-locked typeMap().putIfAbsent.

The field comment at :68-70 says the aliases set is "reassigned by setAliases under the schema mutation lock", which this method never takes.

Repro

Two concurrent ALTER TYPE A ALIASES X / ALTER TYPE B ALIASES X against the same database: both pass existsType("X"), both put, and X resolves to whichever ran second while both types believe they own it. For the second hole, resolve an existing alias repeatedly from another thread while setAliases re-installs a superset: the lookup intermittently fails.

Suggested fix

Wrap the checks and both loops in one recordFileChanges(...) callback, as createProperty and dropProperty now do, and use the write-locked putIfAbsent that rename() uses so the check and the install are one step. Then the field comment at :68 becomes true.

Scope / confidence

Code read. Narrow by nature: it needs concurrent DDL, which is not the common case, and the window is small. Reported because it is the exact pair of holes closed in the sibling mutators, in a method whose own documentation already assumes they were closed here too. What would falsify it: a lock taken by every caller of setAliases above this frame. AlterTypeStatement's aliases arm calls it directly.

Activity

  1. added
    concurrency
    engine
    severity:minor
    on Sep 21, 2026
  2. added this to the 26.10.1 milestone on Sep 21, 2026
  3. added
    in progress
    on Sep 21, 2026
  4. self-assigned this
    on Sep 21, 2026
  5. added a commit that references this issue on Sep 21, 2026
  6. lvca commented on Sep 21, 2026

    @lvca
    Member

    Fixed in #8094, released in 26.10.1.

    ALTER TYPE ... ALIASES checked whether an alias was already taken and then registered it as two separate steps, with no lock in between. Two such statements running at the same time on different types could both pass the check and both register the same alias, leaving two types believing they owned one name.

    A second problem in the same place: setting a new alias list first removed all the previous aliases and only then added the new ones, so a name present in both the old and the new list briefly stopped resolving for anyone reading the schema concurrently.

    Both are fixed. The alias is now reserved in a single atomic step under the schema lock, only aliases actually being dropped are removed, and a rejected ALTER TYPE no longer leaves a half-applied alias list behind.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencyengineseverity:minor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions