usearch icon indicating copy to clipboard operation
usearch copied to clipboard

Bug: golang.NewIndex segfault

Open cpegeric opened this issue 6 months ago • 2 comments

Describe the bug

go version go1.24.3 linux/amd64

These bug ocassionally happens. We got a segfault when call golang.NewIndex with correct parameter {0, 2, 128, 0, 0, 0, false}

SIGSEGV: segmentation violation PC=0x7ff4a394b242 m=19 sigcode=1 addr=0x15c6 signal arrived during cgo execution

goroutine 35218 gp=0xc00be2bdc0 m=19 mp=0xc001001008 [syscall]: runtime.cgocall(0x401c3a0, 0xc00acc2c18) /data/xupeng/code/pkg/mod/golang.org/[email protected]/src/runtime/cgocall.go:167 +0x4b fp=0xc00acc2bf0 sp=0xc00acc2bb8 pc=0x47e0cb github.com/unum-cloud/usearch/golang._Cfunc_usearch_init(0xc02b7dc980, 0xc0384cae08) _cgo_gotypes.go:414 +0x47 fp=0xc00acc2c18 sp=0xc00acc2bf0 pc=0x1a58067 github.com/unum-cloud/usearch/golang.NewIndex.func1(...) /data/xupeng/code/pkg/mod/github.com/unum-cloud/usearch/[email protected]/lib.go:180 github.com/unum-cloud/usearch/golang.NewIndex({0x0, 0x2, 0x80, 0x0, 0x0, 0x0, 0x0}) /data/xupeng/code/pkg/mod/github.com/unum-cloud/usearch/[email protected]/lib.go:180 +0x245 fp=0xc00acc2c98 sp=0xc00acc2c18 pc=0x1a59145 github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw.NewHnswBuildIndex({0xc038c9701a, 0x6}, {{0x53b02d9, 0x4}, {0x0, 0x2, 0x80, 0x0, 0x0, 0x0, ...}, ...}, ...) /home/xupeng/github/matrixone/pkg/vectorindex/hnsw/build.go:68 +0xa5 fp=0xc00acc2ce0 sp=0xc00acc2c98 pc=0x34fb465 github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw.(*HnswBuild).getIndexForAdd(0xc0131c7ba0) /home/xupeng/github/matrixone/pkg/vectorindex/hnsw/build.go:351 +0x33e fp=0xc00acc2e30 sp=0xc00acc2ce0 pc=0x34fcfde github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw.(*HnswBuild).getIndexForAddSync(0x48b6420?) /home/xupeng/github/matrixone/pkg/vectorindex/hnsw/build.go:343 +0x99 fp=0xc00acc2e90 sp=0xc00acc2e30 pc=0x34fcbb9 github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw.(*HnswBuild).addVectorSync(0xc0477bc720?, 0x2630, {0xc029cc3e00, 0x80, 0x80}) /home/xupeng/github/matrixone/pkg/vectorindex/hnsw/build.go:388 +0x27 fp=0xc00acc2ed0 sp=0xc00acc2e90 pc=0x34fd107 github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw.(*HnswBuild).addFromChannel(0xc0131c7ba0, 0xc03abbea80) /home/xupeng/github/matrixone/pkg/vectorindex/hnsw/build.go:286 +0xd6 fp=0xc00acc2f80 sp=0xc00acc2ed0 pc=0x34fc536 github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw.NewHnswBuild.func1() /home/xupeng/github/matrixone/pkg/vectorindex/hnsw/build.go:259 +0x7e fp=0xc00acc2fe0 sp=0xc00acc2f80 pc=0x34fc37e runtime.goexit({}) /data/xupeng/code/pkg/mod/golang.org/[email protected]/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc00acc2fe8 sp=0xc00acc2fe0 pc=0x48a361 created by github.com/matrixorigin/matrixone/pkg/vectorindex/hnsw.NewHnswBuild in goroutine 34912 /home/xupeng/github/matrixone/pkg/vectorindex/hnsw/build.go:254 +0x2b0

Steps to reproduce

IndexConfig = {0, 2, 128, 0, 0, 0, false}

call usearch.NewIndex(IndexConfig{usearch.F32, usearch.L2sq, 128, 0, 0, 0, false})

It is not always reproducible.

Expected behavior

empty index returns without error.

USearch version

v2.17.1

Operating System

Ubuntu 22.04

Hardware architecture

x86

Which interface are you using?

Other bindings

Contact Details

[email protected]

Are you open to being tagged as a contributor?

  • [ ] I am open to being mentioned in the project .git history as a contributor

Is there an existing issue for this?

  • [x] I have searched the existing issues

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

cpegeric avatar Jul 04 '25 12:07 cpegeric

Interesting, @cpegeric! Could you please open a PR draft with a minimal test case added? I'll take a look.

Also, please report the lscpu output on your machine. When the construction doesn't fail, can you please also log the HardwareAcceleration output? Thanks!

ashvardanian avatar Jul 04 '25 13:07 ashvardanian

The PR draft link is https://github.com/unum-cloud/usearch/pull/638

HardwareAcceleration is serial

To compile the usearch library.

(cd usearch-2.17.1 && cmake -B build -DUSEARCH_BUILD_BENCH_CPP=OFF -DUSEARCH_BUILD_TEST_C=OFF -DUSEARCH_BUILD_TEST_CPP=OFF -DUSEARCH_BUILD_LIB_C=ON -DCMAKE_CXX_FLAGS=-I/home/ubuntu/p/matrixone/thirdparties/install/include -DUSEARCH_USE_OPENMP=1 && cmake --build build --config Release)

output of lscpu:

Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 16 On-line CPU(s) list: 0-15 Vendor ID: GenuineIntel Model name: 11th Gen Intel(R) Core(TM) i7-11700 @ 2.50GHz CPU family: 6 Model: 167 Thread(s) per core: 2 Core(s) per socket: 8 Socket(s): 1 Stepping: 1 CPU max MHz: 4900.0000 CPU min MHz: 800.0000 BogoMIPS: 4992.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1g b rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes 64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f 16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept v pid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx avx512f avx512dq rdseed adx smap avx512ifma clflushopt intel_pt avx51 2cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req avx 512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid fsrm md_clear flush_l1d arch_ca pabilities Virtualization features: Virtualization: VT-x Caches (sum of all): L1d: 384 KiB (8 instances) L1i: 256 KiB (8 instances) L2: 4 MiB (8 instances) L3: 16 MiB (1 instance) NUMA: NUMA node(s): 1 NUMA node0 CPU(s): 0-15 Vulnerabilities: Itlb multihit: Not affected L1tf: Not affected Mds: Not affected Meltdown: Not affected Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling Srbds: Not affected Tsx async abort: Not affected

cpegeric avatar Jul 07 '25 12:07 cpegeric