ExportXMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Normal
    • None
    • Affects Version/s: None
    • Component/s: Database
    • None

      The function recursivelyGetAreaParentsWithNames in bookbrainz-data-js/src/func/area.ts uses a recursive CTE to walk the area hierarchy via musicbrainz.l_area_area. When a cycle exists in the area relationships (e.g., area 119788), the query runs forever.

      Impact:
        
      On cesaria, this query ran for 54 days (since 2026-06-17), consuming 100% CPU and 70 GB RAM (56% of the machine's memory).
        
      Root Cause:
        
      The cycle guard WHERE entity0 != descendant only prevents direct self-references, not multi-hop cycles (A→B→C→A). There is also no depth limit on the recursion.
        
      Suggested Fix:
        

      • Add a depth limit (e.g., WHERE depth < 10) to the recursive term
      • And/or use PostgreSQL's CYCLE clause (PG14+) or track visited nodes in an array
      • Also: parameterize areaId to prevent SQL injection (where entity1 = ${areaId} is currently interpolated directly)
          
        File: src/func/area.ts in bookbrainz-data-js (https://github.com/metabrainz/bookbrainz-data-js)

            Assignee:
            Ansh Goyal
            Reporter:
            Zas
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                Version Package