morellon / rrd-ffi

A ruby wrapper for librrd (rrdtool) using ffi.
MIT License
71 stars 20 forks source link

Segfault on wrapper.rb:121 get_array_of_string #8

Closed danhealy closed 12 years ago

danhealy commented 13 years ago

I am getting this segfault pretty often, mac os x running rrdtool 1.4.4, rvm'd ruby 1.9.2-p136. The code that is executing is a series of consecutive rrd.fetch instructions. It is fairly reproducible (it happens almost every time I try a few things), but I haven't found a specific sequence that causes it. In particular, none of the steps on their own cause the segfault, it just happens.

/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/rrd-ffi-0.2.7/lib/rrd/wrapper.rb:121: [BUG] Segmentation fault
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]

-- control frame ----------
c:0043 p:---- s:0223 b:0223 l:000222 d:000222 CFUNC  :get_array_of_string
c:0042 p:0235 s:0218 b:0218 l:000217 d:000217 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/rrd-ffi-0.2.7/lib/rrd/wrapper.rb:121
c:0041 p:0167 s:0199 b:0199 l:000198 d:000198 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/rrd-ffi-0.2.7/lib/rrd/base.rb:52
c:0040 p:0141 s:0193 b:0193 l:000192 d:000192 METHOD /sandbox/skycharts/lib/skycharts.rb:183
c:0039 p:0286 s:0182 b:0182 l:0014f8 d:000181 LAMBDA webapp.rb:92
c:0038 p:---- s:0174 b:0174 l:000173 d:000173 FINISH
c:0037 p:---- s:0172 b:0172 l:000171 d:000171 CFUNC  :call
c:0036 p:0018 s:0169 b:0169 l:002620 d:000168 BLOCK  /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1165
c:0035 p:---- s:0167 b:0167 l:000166 d:000166 FINISH
c:0034 p:---- s:0165 b:0165 l:000164 d:000164 CFUNC  :instance_eval
c:0033 p:0016 s:0162 b:0160 l:000159 d:000159 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:738
c:0032 p:0012 s:0156 b:0156 l:000124 d:000155 BLOCK  /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:722
c:0031 p:0017 s:0154 b:0154 l:000145 d:000153 BLOCK  /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:772
c:0030 p:---- s:0152 b:0152 l:000151 d:000151 FINISH
c:0029 p:---- s:0150 b:0150 l:000149 d:000149 CFUNC  :catch
c:0028 p:0203 s:0146 b:0146 l:000145 d:000145 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:769
c:0027 p:0018 s:0136 b:0136 l:000124 d:000135 BLOCK  /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:721
c:0026 p:---- s:0130 b:0130 l:000129 d:000129 FINISH
c:0025 p:---- s:0128 b:0128 l:000127 d:000127 CFUNC  :each
c:0024 p:0050 s:0125 b:0125 l:000124 d:000124 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:720
c:0023 p:0078 s:0119 b:0119 l:000118 d:000118 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:857
c:0022 p:0009 s:0115 b:0115 l:0007e8 d:000114 BLOCK  /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:648
c:0021 p:---- s:0113 b:0113 l:000112 d:000112 FINISH
c:0020 p:---- s:0111 b:0111 l:000110 d:000110 CFUNC  :instance_eval
c:0019 p:0012 s:0108 b:0108 l:000099 d:000107 BLOCK  /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:822
c:0018 p:---- s:0106 b:0106 l:000105 d:000105 FINISH
c:0017 p:---- s:0104 b:0104 l:000103 d:000103 CFUNC  :catch
c:0016 p:0013 s:0100 b:0100 l:000099 d:000099 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:822
c:0015 p:0155 s:0093 b:0093 l:0007e8 d:0007e8 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:648
c:0014 p:0019 s:0086 b:0086 l:000085 d:000085 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:633
c:0013 p:0032 s:0082 b:0082 l:000081 d:000081 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/commonlogger.rb:18
c:0012 p:0015 s:0074 b:0074 l:000073 d:000073 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/showexceptions.rb:21
c:0011 p:0155 s:0066 b:0066 l:000065 d:000065 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/methodoverride.rb:24
c:0010 p:0018 s:0060 b:0060 l:002550 d:000059 BLOCK  /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1284
c:0009 p:0032 s:0058 b:0058 l:000057 d:000057 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1315
c:0008 p:0011 s:0054 b:0054 l:002550 d:002550 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1284
c:0007 p:0015 s:0050 b:0050 l:000049 d:000049 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/content_length.rb:13
c:0006 p:0338 s:0042 b:0042 l:000041 d:000041 METHOD /Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/handler/webrick.rb:52
c:0005 p:0257 s:0030 b:0030 l:000029 d:000029 METHOD /Users/dan/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:111
c:0004 p:0393 s:0020 b:0020 l:000019 d:000019 METHOD /Users/dan/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:70
c:0003 p:0126 s:0009 b:0009 l:001c48 d:000008 BLOCK  /Users/dan/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/server.rb:183
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:---- s:0002 b:0002 l:000001 d:000001 TOP   
---------------------------
-- Ruby level backtrace information ----------------------------------------
/Users/dan/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
/Users/dan/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/dan/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/handler/webrick.rb:52:in `service'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/content_length.rb:13:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1284:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1315:in `synchronize'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1284:in `block in call'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/methodoverride.rb:24:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/showexceptions.rb:21:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@global/gems/rack-1.2.2/lib/rack/commonlogger.rb:18:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:633:in `call'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:648:in `call!'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:822:in `invoke'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:822:in `catch'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:822:in `block in invoke'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:822:in `instance_eval'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:648:in `block in call!'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:857:in `dispatch!'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:720:in `route!'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:720:in `each'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:721:in `block in route!'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:769:in `process_route'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:769:in `catch'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:772:in `block in process_route'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:722:in `block (2 levels) in route!'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:738:in `route_eval'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:738:in `instance_eval'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1165:in `block in compile!'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/sinatra-1.2.3/lib/sinatra/base.rb:1165:in `call'
webapp.rb:92:in `block in <main>'
/sandbox/skycharts/lib/skycharts.rb:183:in `fetch_time_data'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/rrd-ffi-0.2.7/lib/rrd/base.rb:52:in `fetch'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/rrd-ffi-0.2.7/lib/rrd/wrapper.rb:121:in `fetch'
/Users/dan/.rvm/gems/ruby-1.9.2-p136@skycharts/gems/rrd-ffi-0.2.7/lib/rrd/wrapper.rb:121:in `get_array_of_string'

-- C level backtrace information -------------------------------------------

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap
danhealy commented 13 years ago

I think I figured this one out. If I wrap the call to .fetch around a mutex, it works fine. Is this obvious and I just missed it, or should it be documented?

morellon commented 13 years ago

Sorry for the delay. A mutex shouldn't be needed, supposing rrd_fetch function from librrd is thread safe. I will check librrd for a thread safe function, I know some functions have both thread-safe ad non thread-safe versions. You said it was not happening in one specific step, but can you check if it has something to do with get_array_of_string or from_string methods? Also, which version of ffi are you using?

danhealy commented 13 years ago

It breaks on the same line every time without the mutex, wrapper.rb line 121. Using ffi 1.0.7. Thanks for looking into it.

danhealy commented 13 years ago

I was referring to the order of RRDs accessed when I mentioned it didn't happen at any specific step. The segfault is in the same place.

neilljordan commented 13 years ago

I'm encountering the same segfault in get_array_of_string. Did you find a resolution for this issue?

danhealy commented 13 years ago

Looks like there haven't been any code changes since I opened this issue. My code works by wrapping the call to .fetch with a mutex: http://www.ruby-doc.org/core/classes/Mutex.html

morellon commented 13 years ago

Sorry guys, I didn't have enough time to look into this issue

morellon commented 13 years ago

As I could see. There seems to be a thread safe version of the function. I will code based on it. The function is the following: int rrd_fetch_r ( const char _filename, const char cf, time_t start, time_t end, unsigned long step, unsigned long ds_cnt, char __ds_namv, rrd_value_t *_data);

morellon commented 13 years ago

Hi Guys, I just implemented the fetch using rrd_fetch_r. Could you checkout from the master and test if the issue continues?

morellon commented 12 years ago

Well, I will close this issue. If needed please open a new one.