question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m beginning to experiment with this project—and am likely doing plenty of things wrong—but encountered a cryptic malloc error and program crash after using this library successfully for several experiments. I’m posting what information I have in case this experience represents a stability bug in the code. If it only reflects me using the library incorrectly, my apologies along with appreciation for any tips on better usage.

While ingesting data into an lmdbjava system, it worked successfully for the first 340,000 items ingested, then hard crashed with the following error:

java(7179,0x70001ee7e000) malloc: *** error for object 0x70001ee7cf70: pointer being freed was not allocated
java(7179,0x70001e275000) malloc: *** error for object 0x70001ee7cf70: pointer being freed was not allocated
java(7179,0x70001ee7e000) malloc: *** set a breakpoint in malloc_error_break to debug
java(7179,0x70001e275000) malloc: *** set a breakpoint in malloc_error_break to debug

There was no other error message; no stack trace, etc. Before the error, everything seemed to be working fine. Running this system with a different key/value store (instead of lmdbjava) has worked successfully for a very long time.

The program terminated immediately and ungracefully after printing this message. Some of the data on disk was created during an earlier run of my application which ingested some data (~300,000 key/value pairs) before being shut down normally. Then I restarted and ran the same ingest. My relevant code (in Scala) is below:

val env = org.lmdbjava.Env
    .create()
    .setMapSize(3000485760L)
    .setMaxDbs(32)
    .setMaxReaders(1024)
    .open(new File(path), MDB_WRITEMAP, MDB_NOSYNC, MDB_NOLOCK)

  val db = env.openDbi("foo", org.lmdbjava.DbiFlags.MDB_CREATE)

def persistSnapshot(id: MyID, atTime: Milliseconds, state: Array[Byte]): Future[Unit] = {
    val idBb = ByteBuffer.allocateDirect(id.array.length)
    idBb.put(id.array).flip()
    val stateBb = ByteBuffer.allocateDirect(state.length)
    stateBb.put(state).flip()
    Future(db.put(idBb, stateBb))
  }

  def getLatestSnapshot(id: MyID, upToTime: Option[Milliseconds]): Future[Option[(Milliseconds, Array[Byte])]] = Future{
    val tx = env.txnRead()
    val idBb: ByteBuffer = ByteBuffer.allocateDirect(id.array.length)
    idBb.put(id.array).flip()
    val result = Option(db.get(tx, idBb)).map(r => 0L -> r.array())
    tx.close()
    result
  }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
benalexaucommented, Apr 5, 2019

I just added a Verifier class (see issue #124)for the ByteBuffer buffer type.

You may like to try the 0.6.4-SNAPSHOT (see the Snapshot Repository) with PROXY_OPTIMAL and PROXY_SAFE to get some extra confidence things are working OK on your platform.

BTW thanks for logging this ticket, as it prompted the development of the Verifier. Hopefully it’ll save folks time in the future.

0reactions
benalexaucommented, Apr 4, 2019

Very pleased that you found a solution!

There isn’t much we can do on the Java side to catch a native library SIGSEGV. I think there’s probably more utility in providing an “environment verifier” within LmdbJava that executes a defined sequence of write-then-read operations with successively larger keys, values, transaction sizes and user-nominated durations. That way those suspecting platform bugs can invoke a local method to build confidence their platform is compatible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

malloc error checking methods - Stack Overflow
I have seen a few different ways of doing malloc error checking. Is one way better than the other? Are some exit codes...
Read more >
explain_malloc(3): explain malloc errors - Linux man page
The explain_malloc function is used to obtain an explanation of an error returned by the malloc(3) system call. The least the message will...
Read more >
Four reasons to check what the malloc function returned
If the malloc function is unable to allocate the memory buffer, it returns NULL. Any normal program should check the pointers returned by...
Read more >
Code a Malloc error handling module : r/C_Programming
Why? Errors in malloc() are always critically serious ones. If there is no memory left, or a hardware/kernel failure is preventing memory from ......
Read more >
malloc
The malloc() function shall allocate unused space for an object whose size in ... ERRORS. The malloc() function shall fail if: [ENOMEM]: [Option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found