Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating database with small mapsize produces segfault #36

Open
canadaduane opened this issue Oct 2, 2014 · 7 comments
Open

Creating database with small mapsize produces segfault #36

canadaduane opened this issue Oct 2, 2014 · 7 comments

Comments

@canadaduane
Copy link

$ mkdir lmdb
$ irb -rlmdb
irb(main):001:0> LMDB.new('lmdb', mapsize: 1000)
(irb):1: [BUG] Segmentation fault at 0x00000103a20090
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/CrashReporter
     * /Library/Logs/CrashReporter
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.

-- Control frame information -----------------------------------------------
c:0019 p:---- s:0077 e:000076 CFUNC  :new
c:0018 p:0019 s:0072 e:000071 EVAL   (irb):1 [FINISH]
c:0017 p:---- s:0070 e:000069 CFUNC  :eval
c:0016 p:0024 s:0063 e:000062 METHOD /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/workspace.rb:86
c:0015 p:0025 s:0056 e:000054 METHOD /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/context.rb:380
c:0014 p:0022 s:0050 e:000049 BLOCK  /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:492
c:0013 p:0040 s:0042 e:000041 METHOD /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:624
c:0012 p:0009 s:0037 e:000036 BLOCK  /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:489
c:0011 p:0118 s:0033 e:000032 BLOCK  /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:247 [FINISH]
c:0010 p:---- s:0030 e:000029 CFUNC  :loop
c:0009 p:0007 s:0027 e:000026 BLOCK  /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:233 [FINISH]
c:0008 p:---- s:0025 e:000024 CFUNC  :catch
c:0007 p:0015 s:0021 e:000020 METHOD /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:232
c:0006 p:0030 s:0018 E:001308 METHOD /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:488
c:0005 p:0008 s:0015 e:000014 BLOCK  /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:397 [FINISH]
c:0004 p:---- s:0013 e:000012 CFUNC  :catch
c:0003 p:0143 s:0009 E:0015e8 METHOD /Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:396
c:0002 p:0021 s:0004 E:001cf8 EVAL   /Users/duane/.rbenv/versions/2.1.3/bin/irb:11 [FINISH]
c:0001 p:0000 s:0002 E:002058 TOP    [FINISH]

/Users/duane/.rbenv/versions/2.1.3/bin/irb:11:in `<main>'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:396:in `start'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:396:in `catch'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:397:in `block in start'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:488:in `eval_input'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `catch'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `loop'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/ruby-lex.rb:247:in `block (2 levels) in each_top_level_statement'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:489:in `block in eval_input'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:624:in `signal_status'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb.rb:492:in `block (2 levels) in eval_input'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/context.rb:380:in `evaluate'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/workspace.rb:86:in `evaluate'
/Users/duane/.rbenv/versions/2.1.3/lib/ruby/2.1.0/irb/workspace.rb:86:in `eval'
(irb):1:in `irb_binding'
(irb):1:in `new'

-- C level backtrace information -------------------------------------------
0   ruby                                0x00000001033eb656 rb_vm_bugreport + 134
1   ruby                                0x00000001032a00e3 report_bug + 307
2   ruby                                0x000000010329ffa4 rb_bug + 180
3   ruby                                0x000000010336e109 sigsegv + 153
4   libsystem_platform.dylib            0x00007fff943e15aa _sigtramp + 26
5   lmdb_ext.bundle                     0x00000001036fd10f mdb_env_pick_meta + 31
6   ???                                 0x00007fff5c99b830 0x0 + 140734746966064

@vjoel
Copy link
Collaborator

vjoel commented Oct 2, 2014

Not getting that here:

$ irb -r lmdb
>> LMDB.new('lmdb', mapsize: 1000)
=> #<LMDB::Environment:0x007fa6daf21420>
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
Linux smeg 3.13.0-36-generic #63-Ubuntu SMP Wed Sep 3 21:30:07 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 

Did you do anything special to install liblmdb separately from the gem, or did you install only the gem (which should be fine)?

@canadaduane
Copy link
Author

I didn't install liblmdb separately, just through the gem.

Also, I installed the gem on a 2nd Mac OS X system and received the same result.

Did you try creating an empty directory first? I get two different results (although, not the same as yours) depending on the state of the dir:

$ mkdir db  # <-- empty dir
$ irb -rlmdb
irb(main):001:0> db = LMDB.new('db', mapsize: 1000)
(irb):1: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]
# ... etc ...
$ rm -rf db
$ irb -rlmdb
irb(main):001:0> LMDB.new('db', mapsize: 1000)
LMDB::Error: No such file or directory
    from (irb):1:in `new'
    from (irb):1
    from /Users/duane/.rbenv/versions/1.9.3-p194/bin/irb:12:in `<main>'

@vjoel
Copy link
Collaborator

vjoel commented Oct 2, 2014

The second error is expected. LMDB.new doesn't try to create a directory.

Are you seeing similar errors with larger mapsize values? The default is 1MB.

@canadaduane
Copy link
Author

Not for very large sizes. I tried several sizes, though, and it looks like 4100 is the smallest size I can go without a segfault.

Maybe we're hitting a 4096 byte bug?

lmdb_test.rb:

require 'fileutils'

size = 1_000_000

while size > 0
  FileUtils.rm_rf 'db'
  FileUtils.mkdir 'db'
  puts size
  db = LMDB.new('db', mapsize: size)
  db.close
  size -= 100
end

Running with ruby -rlmdb lmdb_test.rb:

# ...
5000
4900
4800
4700
4600
4500
4400
4300
4200
4100
4000
lmdb_test.rb:9: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]

-- Control frame information -----------------------------------------------
c:0004 p:---- s:0013 b:0013 l:000012 d:000012 CFUNC  :new
c:0003 p:0100 s:0008 b:0008 l:001dc8 d:001728 EVAL   lmdb_test.rb:9
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:001dc8 d:001dc8 TOP   

@vjoel
Copy link
Collaborator

vjoel commented Oct 3, 2014

Maybe it's a bug of MDB specific to osx?

Can you recreate this with a C program?

@canadaduane
Copy link
Author

It's certainly possible. I don't have the time to work further on this, but
thanks for your help.
On Oct 3, 2014 5:03 PM, "Joel VanderWerf" notifications@github.com wrote:

Maybe it's a bug of MDB specific to osx?

Can you recreate this with a C program?


Reply to this email directly or view it on GitHub
#36 (comment).

@richardgolding
Copy link
Contributor

One possible clue: the page size on OS X is 4k.

-r

On Oct 3, 2014, at 6:54 PM, Duane Johnson notifications@github.com wrote:

It's certainly possible. I don't have the time to work further on this, but
thanks for your help.
On Oct 3, 2014 5:03 PM, "Joel VanderWerf" notifications@github.com wrote:

Maybe it's a bug of MDB specific to osx?

Can you recreate this with a C program?


Reply to this email directly or view it on GitHub
#36 (comment).


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants