BlackyDrum / chromadb-cpp

Easily interact with ChromaDB Vector Database in C++
MIT License
9 stars 2 forks source link

Fatal glibc error: pthread_mutex_lock.c:94 error when including ollama.hpp #9

Open briefnotion opened 4 weeks ago

briefnotion commented 4 weeks ago

Hello. Your ChromaDB looks very interesting and I spent a good amount of time trying to pull it into my little hobby project. Unfortunately, I'm at that point where the error is beyond my comprehension.

After trying numerous things, such as, modifying the CMakeFile.txt, isolating the libraries, and commenting out most of the program to just a few lines of code, I was able to isolate my problem to:

#include "ollama.hpp"

and

chromadb::Client client("http", "localhost", "8000");

seems that if the library ollama.hpp is not included, or commented out, I can get expected results of:

Print Info
0.5.15
1730359702407966699

from:

  chromadb::Client client("http", "localhost", "8000");

  cout << "Print Info" << endl;
    std::cout << client.GetVersion() << std::endl;
    std::cout << client.GetHeartbeat() << std::endl;

but if I #include "ollama.hpp"

the results are:

Fatal glibc error: pthread_mutex_lock.c:94 (___pthread_mutex_lock): assertion failed: mutex->__data.__owner == 0

Would you happen to know if this is a fault in my code, ollama.hpp, or chromadb-cpp.

You are welcomed to look at my code in the github repo titled "ollama_chat" if you think it would help. Please, don't judge.

BlackyDrum commented 4 weeks ago

Hello!

I'm actually not quite sure about this error. The issue seems to stem from a conflict between the versions of the httplib library used by both ollama-hpp and chromadb-cpp, which results in mutex clashes when both libraries are included.

I found a (very dirty) workaround that resolves the assertion failure. Here’s how to implement it:

  1. Use the Single Header File Provided by ollama-hpp
    • Create a directory named include in your project root.
    • Move the single header file ollama.hpp into the include directory.
      1. Update Your CMake Configuration
    • Modify your CMakeLists.txt file to include the new header directory. Ensure it looks like this:
      
      # ...

include_directories( ../include )

...

Include directories

target_include_directories(chatapi PRIVATE ../include ${ChromaDB_INCLUDE_DIR} ${OpenSSL_INCLUDE_DIR} )

...



3. **Modify the `ollama.hpp` File**
- Open the `ollama.hpp` file and remove the section related to `httplib`. Specifically, delete everything from line **_24792_** to the end of the file. This prevents the potential conflicts caused by multiple definitions or mutex handling from both libraries.
4. **Build** with `./cmak.sh` and `./m`

I will further investigate the issue to find a cleaner and more sustainable solution.
briefnotion commented 3 weeks ago

I'm still working on my mutex problem. I followed your instructions and I am not able to complete the 3rd step because we may be looking at different things. You said I should "delete everything from line 24792 to the end of the file," According to my ollama.hpp source "ollama.hpp" only has 1046 lines. I suspect you may be looking at all the code as one file, but I can't say for sure.

BlackyDrum commented 3 weeks ago

When I refer to ollama.hpp, I’m talking about the single-header include file, which you can find here: https://github.com/jmont-dev/ollama-hpp/blob/master/singleheader/ollama.hpp

BlackyDrum commented 3 weeks ago

I just realized that this solution won't work either, I'll try to find another way

briefnotion commented 3 weeks ago

Awesome. Thank you. I'll keep checking back here to see if it was resolved.