thaliproject / jxcore

Evented IO for Chakra, SpiderMonkey & V8 JavaScript
http://jxcore.com
Other
12 stars 4 forks source link

Unallocated pointer freed error #12

Open yaronyg opened 8 years ago

yaronyg commented 8 years ago

We are getting the following error during tests: jx(1068,0x105751000) malloc: * error for object 0xa6e00786a2e65: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

To repro:

  1. git clone https://github.com/thaliproject/Thali_CordovaPlugin.git
  2. git checkout malloc_error
  3. cd thali/install/
  4. jx npm run setupDesktop
  5. cd ../../test/www/jxcore
  6. jx npm test

It will core dump with the error above pretty quickly.

enricogior commented 8 years ago

On what platform is it happening?

enricogior commented 8 years ago

Is step 4 correct?

enricogior commented 8 years ago

What jxcore version has been installed?

andrew-aladev commented 8 years ago

This bug works in osx.

enricogior commented 8 years ago

@andrew-aladev thanks.

andrew-aladev commented 8 years ago

When you are in test/www/jxcore you can reproduce this by jx runTests.js bv_tests/testPouchDBGenerator.js

enricogior commented 8 years ago

Just to make sure: jx is using V8?

andrew-aladev commented 8 years ago

My jx was installed using new gist.

jx -jxv
> v0.3.1.2
jx -jsv
> Google V8 v3.14.5.9
enricogior commented 8 years ago

OK, thanks.

enricogior commented 8 years ago

I started the investigation, I can repro the bug on macOS, while on Linux the bug is not present.

enricogior commented 8 years ago
* thread #6: tid = 0x8acaa, 0x00007fff93a21f2e libsystem_malloc.dylib`malloc_error_break, stop reason = breakpoint 1.1
  * frame #0: 0x00007fff93a21f2e libsystem_malloc.dylib`malloc_error_break
    frame #1: 0x00007fff93a12fd2 libsystem_malloc.dylib`free + 314
    frame #2: 0x00000001001ea351 jx`leveldown::AsyncWorker::SetStatus(leveldb::Status) [inlined] leveldb::Status::operator=(s=0x0000700000541e78) + 28 at status.h:99
    frame #3: 0x00000001001ea335 jx`leveldown::AsyncWorker::SetStatus(this=0x00000001018005b0, status=(state_ = 0x0000000000000000)) + 17 at async.h:34
    frame #4: 0x00000001057063cd leveldown.node`leveldown::OpenWorker::Execute(this=0x00000001018005b0) + 51 at database_async.cc:54
    frame #5: 0x00000001002085bf jx`worker(arg=<unavailable>) + 90 at threadpool.c:68
    frame #6: 0x00000001001fe9ac jx`uv__thread_start(ctx_v=<unavailable>) + 25 at uv-common.c:282
    frame #7: 0x00007fff88ad799d libsystem_pthread.dylib`_pthread_body + 131
    frame #8: 0x00007fff88ad791a libsystem_pthread.dylib`_pthread_start + 168
    frame #9: 0x00007fff88ad5351 libsystem_pthread.dylib`thread_start + 13
inline void Status::operator=(const Status& s) {
  // The following condition catches both aliasing (when this == &s),
  // and the common case where both s and *this are ok.
  if (state_ != s.state_) {
    delete[] state_;
    state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
  }
}
enricogior commented 8 years ago

@andrew-aladev the test requires leveldown-mobile, but when running on macOS, it's using leveldown, as you can see from the stack trace. If I remove node_modules/leveldown, the test passes. I'm a little bit lost here.

$ jx runTests.js bv_tests/testPouchDBGenerator.js
Test runner loading file: /Users/cicoriasmbp13/build/Thali_CordovaPlugin/test/www/jxcore/bv_tests/testPouchDBGenerator.js
TAP version 13
# setup
# test defaultDirectory
ok 1 should be equal
ok 2 should be equal
ok 3 should be equal
# teardown
# setup
# test defaultAdapter
ok 4 should be equal
ok 5 should be equal
ok 6 should be equal
ok 7 should be equal
ok 8 should be equal
ok 9 should be equal
ok 10 should be equal
ok 11 should be equal
# teardown

1..11
# tests 11
# pass  11

# ok

P.S. On Linux it uses leveldown-mobile.

yaronyg commented 8 years ago

This is a bug and we do need to fix it but we are kicking down the priority. We need to make sure we don't call the wrong leveldown.

yaronyg commented 8 years ago

So what is almost certainly happening here is that at some point we installed PouchDB or Express-PouchDB using node which would cause us to bring in leveldown. Then we used JX to run some tests in the same directory. But Pouch still prefers leveldown to leveldown-mobile and so boom. I think we now avoid this because we hard coded our dependency on leveldown-mobile when we call PouchDB. But in any case we have a work around (delete node_modules/leveldown) so I'm kicking this to Icebox for now.