Skip to content

Fix concurrency bugs and UDF correctness issues found in PR #76 review#78

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/review-pull-request
Closed

Fix concurrency bugs and UDF correctness issues found in PR #76 review#78
Copilot wants to merge 3 commits intomainfrom
copilot/review-pull-request

Conversation

Copy link

Copilot AI commented Feb 25, 2026

Review of PR #76 (component migration 8.4–9.6) uncovered several pre-existing bugs in the plugin code. This PR applies those fixes and a few structural cleanups to the main plugin sources.

Bug Fixes

  • VectorIndexCollection::open() missing shared lockget() acquires lockShared() before returning; open() did not, so SharedLockGuard would call unlockShared() on a never-locked mutex (UB) in any code path that creates a new index via open() then drops or scopes out normally.

  • myvector_ann_set_init: null-before-lock orderingSharedLockGuard l(vi) was constructed before the if (!vi) null check, passing a potentially-null pointer to the guard. Reordered to check null first. Also improves the error message to include the missing index name.

  • myvector_display: returns string literal from UDFreturn "<invalid vector>" on checksum failure returned a pointer to a read-only string literal instead of writing to the initid->ptr result buffer, causing incorrect behavior or crashes in MySQL's UDF return path.

  • Format string mismatch%d used for colinfo.length() (size_t) → UB on LP64 platforms. Fixed to %zu.

Structural Changes

  • SharedLockGuard moved to include/myvector.h — required for upcoming component build sources. Added deleted copy/move, explicit constructor, renamed clear()release().
  • BITS_PER_BYTE moved to header — was static const local to myvector.cc; promoted to constexpr in the shared header.
  • MYVECTOR_UDF_METADATA() macro — abstracts the UDF metadata service accessor; needed for the component build path in PR Component migration (8.4–9.6) and release workflow update #76 where myvector_component_udf_metadata replaces (*h_udf_metadata_service).

Design Note on SharedLockGuard

PR #76 proposed having SharedLockGuard acquire lockShared() in its constructor. This was not applied here: get() already acquires the shared lock before returning (to close the race window while m_mutex is held), so adding a second lockShared() in the guard constructor would double-acquire std::shared_mutex from the same thread — UB per C++17. The correct fix is ensuring open() also acquires the lock (done here), keeping the guard as release-only.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 25, 2026 13:50
- Move BITS_PER_BYTE and SharedLockGuard to include/myvector.h for
  broader access and cleaner architecture
- Add #include <vector> to myvector.h (missing include)
- Improve SharedLockGuard: rename clear() to release(), add deleted
  copy/move, make constructor explicit
- Fix: VectorIndexCollection::open() now acquires shared lock before
  returning (matching get() behavior), preventing UB when SharedLockGuard
  releases a lock never acquired on the open() path
- Fix: myvector_ann_set_init moves lock guard creation after null check
  to avoid constructing guard with null index
- Fix: improve ER_MYVECTOR_INDEX_NOT_FOUND message to include index name
- Fix: myvector_display returns string literal instead of writing to UDF
  result buffer (fixes invalid memory access)
- Fix: format string %d -> %zu for size_t colinfo.length()

Co-authored-by: askdba <5901296+askdba@users.noreply.github.com>
…atibility

The PR #76 introduces a macro to abstract UDF metadata service access,
preparing for component builds where the service is accessed differently.
This aligns with the component migration plan in docs/COMPONENT_MIGRATION_PLAN.md.

Co-authored-by: askdba <5901296+askdba@users.noreply.github.com>
Copilot AI changed the title [WIP] Review open pull request for changes Fix concurrency bugs and UDF correctness issues found in PR #76 review Feb 25, 2026
Copilot AI requested a review from askdba February 25, 2026 13:54
@askdba
Copy link
Owner

askdba commented Feb 25, 2026

Closing: bug fixes incorporated into feature/component-migration-8.4-9.6 branch. That branch has component migration work and will be merged to main, making this PR redundant and conflicted.

askdba added a commit that referenced this pull request Feb 25, 2026
- SharedLockGuard: make release-only (no acquire in constructor) to avoid
  double-lock when used with get() which already acquires before returning
- VectorIndexCollection::open(): acquire lockShared() before returning to
  match get() behavior; SharedLockGuard expects caller to hold lock
- Keeps component build intact (PR #78 targeted main without component)

Co-authored-by: Cursor <cursoragent@cursor.com>
@askdba askdba closed this Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants