Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Reject by-id transaction access from an environment that does not own the transaction

Open
#886 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, node.js, typescript
Domain
backend, databases

Research direction

Start with Store.getTxnId() in src/store.ts:1206 and the ownership/state handling in transaction_handle.cpp and transaction.cpp. Trace the by-id entry points listed in database.cpp, db_iterator.cpp, and transaction_log_handle.cpp, then compare with test/abandon-writes.test.ts. Done means cross-environment transaction access is covered by tests and is rejected consistently without weakening same-environment behavior.

Written by the indexing model from the issue text.

Description

A transaction created in one worker_threads environment can be reached from another environment by its id, and nothing orders that access against the owning environment or the commit lane. A RocksDB Transaction is not thread-safe, so a concurrent write through it is undefined behavior: heap corruption, or an acknowledged write that never lands.

Found while fixing the writesAbandoned data race in #876. That fix made one field well-defined; #884 rewrote the field's comment to say explicitly that the handle is not synchronized. This issue tracks the rest.

Mechanism

  • Transaction ids resolve through the process-global DBDescriptor (transactionGet(txnId)), shared by every environment that opens the path.
  • Store.getTxnId() (src/store.ts:1206) only checks that transaction.store.identityPath matches the database. A { transaction: { id, store: { identityPath } } } object built in another worker passes it.
  • TransactionHandle::putSync / removeSync then read the plain state field (transaction_handle.cpp:783, :834). That read has no happens-before edge to the owner's Committing store (transaction.cpp:976) or the commit lane's Committed store (:648), so it can see a stale Pending.
  • The foreign environment then calls txn->Put / Delete concurrently with the lane's txn->Commit() or resetTransaction(), or with the owner's own staging on its JS thread.

Affected entry points (by-id lookups on main)

Entry point Location
Database::Get src/binding/database/database.cpp:1100
Database::GetCount database.cpp:1412
Database::GetSync database.cpp:1864
Database::PutSync database.cpp:2569
Database::RemoveSync database.cpp:2656
transactional iterator setup src/binding/iterator/db_iterator.cpp:165
TransactionLog.addEntry src/binding/transaction_log/transaction_log_handle.cpp:35

The writes are the corruption risk. The reads race the same txn against a concurrent commit or reset.

Suggested fix

Enforce the ownership invariant rather than adding atomics field by field: record the owning napi_env on TransactionHandle at creation, and reject a by-id lookup from any other environment at each entry point above (throwing, for example, ERR_TRANSACTION_WRONG_ENV). Doing this per field would still leave txn, the touched-family set and the VT intents unsynchronized.

Open question

Whether any supported caller, Harper in particular, passes transaction ids across workers is unverified. The reviewer who traced this expects not. If none does, rejection is safe. If one does, the fix has to serialize access instead.

Not covered by #876 / #884

test/abandon-writes.test.ts covers same-environment publication only. No test exercises by-id access from another environment.

Dominant language
C++
Stars
24
Forks
3
Avg merge
1d 7h
Merged PRs (30d)
49

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HarperFast/rocksdb-js

All issues in HarperFast/rocksdb-js

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.