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

Possible to check for results before #fetch(:hash)? (segfault) #47

Closed
plainlystated opened this issue Apr 14, 2016 · 3 comments
Closed

Comments

@plainlystated
Copy link

I'm getting a segfault if I do a query that has no results and then try to #fetch it. Is there a way to safely check if a result exists before doing a #fetch?

Thanks,
Patrick

For example (a result is found):

$ rails runner "p Firebird::Address._connection.execute('select ADDRESS_ID from TBL_ADDRESS where ADDRESS_ID = 1').fetch(:hash)"

{"ADDRESS_ID"=>1}

(no result found, segfault):

$ rails runner "p Firebird:Address._connection.execute('select ADDRESS_ID from TBL_ADDRESS where ADDRESS_ID = 9999').fetch(:hash)" 2>&1 | head -50

/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/runner.rb:62: [BUG] Segmentation fault at 0x00000000000008
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0012 p:---- s:0045 e:000044 CFUNC  :fetch
c:0011 p:0022 s:0041 e:000039 EVAL   /home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/runner.rb:62 [FINISH]
c:0010 p:---- s:0038 e:000037 CFUNC  :eval
c:0009 p:0258 s:0031 E:000ff0 TOP    /home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/runner.rb:62 [FINISH]
c:0008 p:---- s:0027 e:000026 CFUNC  :require
c:0007 p:0014 s:0023 E:000968 METHOD /home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123
c:0006 p:0009 s:0019 E:0009f0 METHOD /home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:90
c:0005 p:0033 s:0016 E:000a88 METHOD /home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39
c:0004 p:0116 s:0012 E:001750 TOP    /home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands.rb:17 [FINISH]
c:0003 p:---- s:0008 e:000007 CFUNC  :require
c:0002 p:0034 s:0004 E:0025d0 EVAL   bin/rails:4 [FINISH]
c:0001 p:0000 s:0002 E:000f00 TOP    [FINISH]

-- Ruby level backtrace information ----------------------------------------
bin/rails:4:in `<main>'
bin/rails:4:in `require'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:90:in `runner'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:123:in `require'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/runner.rb:62:in `<top (required)>'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/runner.rb:62:in `eval'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/runner.rb:62:in `<top (required)>'
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/railties-4.2.0/lib/rails/commands/runner.rb:62:in `fetch'

-- Machine register context ------------------------------------------------
 RIP: 0x00007fbee4127290 RBP: 0x0000000000000001 RSP: 0x00007fffe5f80288
 RAX: 0x00000000069aeb50 RBX: 0x0000000000000000 RCX: 0x0000000000002000
 RDX: 0x0000000000000000 RDI: 0x0000000000000008 RSI: 0x0000000000000000
  R8: 0x0000000000000000  R9: 0x00007fbee47d8138 R10: 0x0000000000000000
 R11: 0x00007fbee3eb7870 R12: 0x00000000069aeb78 R13: 0x00000000069aeab0
 R14: 0x0000000000000008 R15: 0x00000000069aeb50 EFL: 0x0000000000010206

-- C level backtrace information -------------------------------------------
/home/patrick/.rvm/rubies/ruby-2.2.1/bin/../lib/libruby.so.2.2(rb_vm_bugreport+0x51f) [0x7fbee42e02bf] vm_dump.c:693
/home/patrick/.rvm/rubies/ruby-2.2.1/bin/../lib/libruby.so.2.2(rb_bug_context+0xcb) [0x7fbee4173ddb] error.c:425
/home/patrick/.rvm/rubies/ruby-2.2.1/bin/../lib/libruby.so.2.2(sigsegv+0x3e) [0x7fbee4253b7e] signal.c:879
/lib/x86_64-linux-gnu/libc.so.6 [0x7fbee3d67d40]
[0x7fbee4127290]
/home/patrick/.rvm/gems/ruby-2.2.1@workbench/gems/fb-0.7.4/fb.so(cursor_fetch+0xce) [0x7fbed37261be] fb.c:2340
/home/patrick/.rvm/rubies/ruby-2.2.1/bin/../lib/libruby.so.2.2(vm_call_cfunc+0x11e) [0x7fbee42c7b7e] vm_insnhelper.c:1382
/home/patrick/.rvm/rubies/ruby-2.2.1/bin/../lib/libruby.so.2.2(vm_call_method+0x11e) [0x7fbee42de78e] vm_insnhelper.c:1691
/home/patrick/.rvm/rubies/ruby-2.2.1/bin/../lib/libruby.so.2.2(vm_exec_core+0x25c2) [0x7fbee42cf622] insns.def:1054
@plainlystated plainlystated changed the title Possible to check for results before #fetch? (segfault) Possible to check for results before #fetch(:hash)? (segfault) Apr 14, 2016
@plainlystated
Copy link
Author

Looks like it's specific to #fetch(:hash):

$ rails runner "p Firebird::Address._connection.execute('select ADDRESS_ID from TBL_ADDRESS where ADDRESS_ID = 9999').fetch"

nil

fetch_all is doing a nil check before returning results, so I that may be what we need here:
https://github.com/rowland/fb/blob/master/fb.c#L2202

@rowland
Copy link
Owner

rowland commented Apr 14, 2016

Thank you. Version 0.7.5 returns nil instead.

@plainlystated
Copy link
Author

I've confirmed that 0.7.5 fixes the issue. Thanks for the quick turnaround!

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

2 participants