Segfault using threads

git clone https://github.com/cbjs-dev/cbjs.git
cd cbjs
nvm install && nvm use
git checkout vitest/keyspace-isolation
npm ci -ws --include-workspace-root
vitest kv --project=project:keyspace-isolation --run --no-file-parallelism -t "insert"

Most of the time, you will get a segfault :

PID 24983 received SIGSEGV for address: 0x8caf0
0   segfault-handler.node               0x0000000105ee5184 _ZL16segfault_handleriP9__siginfoPv + 296
1   libsystem_platform.dylib            0x000000018d7d7584 _sigtramp + 56
2   couchbase-native.node               0x0000000120d54108 _ZN9couchbase4core6bucket6map_idERKNS0_11document_idE + 60
3   couchbase-native.node               0x0000000120e22f3c _ZN4asio6detail17executor_function8completeINS0_7binder1IZN9couchbase4core10operations12mcbp_commandINS5_6bucketENS6_17increment_requestEE25handle_unknown_collectionEvEUlNSt3__110error_codeEE_SC_EENSB_9allocatorIvEEEEvPNS1_9impl_baseEb + 10732
4   couchbase-native.node               0x0000000120e22758 _ZN4asio6detail17executor_function8completeINS0_7binder1IZN9couchbase4core10operations12mcbp_commandINS5_6bucketENS6_17increment_requestEE25handle_unknown_collectionEvEUlNSt3__110error_codeEE_SC_EENSB_9allocatorIvEEEEvPNS1_9impl_baseEb + 8712
5   couchbase-native.node               0x0000000120d6b164 _ZNK9couchbase4core7cluster7executeENS0_10operations14insert_requestEONS0_5utils16movable_functionIFvNS2_15insert_responseEEEE + 792
6   couchbase-native.node               0x0000000120e2aa00 _ZN4asio6detail17executor_function8completeINS0_7binder1IZN9couchbase4core10operations12mcbp_commandINS5_6bucketENS6_14insert_requestEE25handle_unknown_collectionEvEUlNSt3__110error_codeEE_SC_EENSB_9allocatorIvEEEEvPNS1_9impl_baseEb + 7924
7   couchbase-native.node               0x0000000120d9452c _ZN4asio6detail11executor_opINS0_7binder0INS_15executor_binderIZN9couchbase4core12cluster_impl5closeEONS5_5utils16movable_functionIFvvEEEEUlvE_NS_10io_context19basic_executor_typeINSt3__19allocatorIvEELm0EEEEEEESH_NS0_19scheduler_operationEE11do_completeEPvPSL_RKNSF_10error_codeEm + 3396
8   couchbase-native.node               0x0000000120d5a6a0 _ZN4asio6detail11executor_opINS0_7binder0INS_15executor_binderIZZN9couchbase4core11bucket_impl9bootstrapEONS5_5utils16movable_functionIFvNSt3__110error_codeENS5_8topology13configurationEEEEENUlSA_SC_E_clESA_SC_EUlvE0_NS_10io_context19basic_executor_typeINS9_9allocatorIvEELm0EEEEEEESL_NS0_19scheduler_operationEE11do_completeEPvPSP_RKSA_m + 140
9   couchbase-native.node               0x0000000120d0de80 asio_detail_posix_thread_function + 1584
10  couchbase-native.node               0x0000000120d0d9b0 asio_detail_posix_thread_function + 352
11  couchbase-native.node               0x0000000120d0e33c asio_detail_posix_thread_function + 2796
12  libsystem_pthread.dylib             0x000000018d7a6f94 _pthread_start + 136
13  libsystem_pthread.dylib             0x000000018d7a1d34 thread_start + 8
[1]    24983 segmentation fault  vitest kv --project=project:keyspace-isolation --run --no-file-parallelism -t

You can change the connection params in vitest.config.ts.

% vitest kv --project=project:keyspace-isolation --run --no-file-parallelism -t “insert”
zsh: command not found: vitest

I had to do some gymnastics to install nvm and maybe I messed up. What did I miss?

It seems that the nvm install and nvm use commands take a version. I used v21.7.3

using the vitest that I find in node_modules…

node_modules/.bin/vitest kv --project=project:keyspace-isolation --run --no-file-parallelism -t “insert”

After doing “npm run build” it finds the test and gives the output below.

After creating store.library.books (100Mib) and setting the size of the cbjs bucket being created to 100Mib it runs fine with the exception of “Tests closed successfully but something prevents the main process from exiting”. I’m guessing that a cluster is not being closed.

./node_modules/.bin/vitest kv --project=project:keyspace-isolation --run --no-file-parallelism -t “insert”

RUN v1.5.0 /Users/michaelreiche/cbj/cbjs

(node:36719) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
stdout | tests/kv.spec.ts > kv > should isolate an insert
{ title: ‘insert’ }

✓ |project:keyspace-isolation| tests/kv.spec.ts (2) 2333ms
✓ kv (2) 2072ms
✓ should isolate an insert 2072ms
↓ should isolate a get [skipped]

Test Files 1 passed (1)
Tests 1 passed | 1 skipped (2)
Start at 10:40:20
Duration 5.79s (transform 1.68s, setup 569ms, collect 5ms, tests 2.33s, environment 0ms, prepare 1.72s)

HTML Report is generated
You can run npx vite preview --outDir tests-report to see the test results.
close timed out after 10000ms
Tests closed successfully but something prevents the main process from exiting
You can try to identify the cause by enabling “hanging-process” reporter. See Configuring Vitest | Vitest

Does the error only occur when the collection doesn’t exist?

The test should succeed without creating the keyspace. It is created on demand.

I have reproduced the issue with node 18, 20 and 21 on MacOS.
On linux (GitHub Actions), I have a core dump but for some reason the segfault is not logged. See workflow run.

PS: If you retry, be careful because I’ve migrated to pnpm on this very branch. Use npx npkill to remove all node_modules and then run pnpm i

my issue with the the buckets was that I didn’t have enough space in my cluster to create the cbjs_xxx bucket. I don’t think the store bucket is ever accessed. I added some logging just to make sure the code-paths were being executed. It runs fine. Note that I am using node v21.7.1. I’ve ran it on a single-node cluster and a three-node cluster. Enabling trace logging might help you with trouble-shooting. export CBPPLOGLEVEL=trace

 % ./node_modules/.bin/vitest kv --project=project:keyspace-isolation --run --no-file-parallelism -t "insert" 
RUN  v1.5.0 /Users/michaelreiche/cbj/cbjs

(node:96558) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
stdout | tests/kv.spec.ts > kv > should isolate an insert
inserting...
Collection {
  DEFAULT_NAME: '_default',
  scope: Scope {
    bucket: Bucket { cluster: [Cluster], name: 'store', conn: Connection {} },
    name: 'library',
    conn: Connection {}
  },
  name: 'books',
  conn: Connection {},
  kvScanTimeout: 75000,
  scanBatchItemLimit: 50,
  scanBatchByteLimit: 15000
}

stdout | tests/kv.spec.ts > kv > should isolate an insert
inserted
MutationResult {
  cas: Cas<1714058878347444224>,
  token: MutationToken<cbjs_store_8272bd09:10:89946137241247:6>
}

stdout | tests/kv.spec.ts > kv > should isolate an insert
content
{ title: 'insert' }

 ✓ |project:keyspace-isolation| tests/kv.spec.ts (2) 4313ms
   ✓ kv (2) 3284ms
     ✓ should isolate an insert 3284ms
     ↓ should isolate a get [skipped]

 Test Files  1 passed (1)
      Tests  1 passed | 1 skipped (2)
   Start at  08:27:53
   Duration  6.74s (transform 1.22s, setup 417ms, collect 5ms, tests 4.31s, environment 0ms, prepare 1.33s)

 HTML  Report is generated
       You can run npx vite preview --outDir tests-report to see the test results.
close timed out after 10000ms
Tests closed successfully but something prevents the main process from exiting
You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reporters
michaelreiche@C02C2172MD6V cbjs % pwd
/Users/michaelreiche/cbj/cbjs
cbjs % node --version
v21.7.1

I find it odd that in your stack trace, increment_request is reference from insert_request.

4   couchbase-native.node               0x0000000120e22758 _ZN4asio6detail17executor_function8completeINS0_7binder1IZN9couchbase4core10operations12mcbp_commandINS5_6bucketENS6_17increment_requestEE25handle_unknown_collectionEvEUlNSt3__110error_codeEE_SC_EENSB_9allocatorIvEEEEvPNS1_9impl_baseEb + 8712
5   couchbase-native.node               0x0000000120d6b164 _ZNK9couchbase4core7cluster7executeENS0_10operations14insert_requestEONS0_5utils16movable_functionIFvNS2_15insert_responseEEEE + 792
(ins)cbjs $ npm ci -ws --include-workspace-root
npm ERR! No workspaces found!

npm ERR! A complete log of this run can be found in:
npm ERR!     $HOME/.npm/_logs/2024-04-25T18_52_22_911Z-debug-0.log
37 verbose Darwin 23.4.0
38 verbose node v18.13.0
39 verbose npm  v8.19.3

In my last post I mentioned that I moved to pnpm and included the steps to make the change too.
@avsej do you mind giving it another go ?

@mreiche No more segfault after upgrading to the latest 4.3.1 binaries :ok_hand:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.