Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Segmentation fault #20

Closed
agarbutt opened this Issue · 13 comments

3 participants

Andy Garbutt Kubo Takehiro Edgars Beigarts
Andy Garbutt

I have a segmentation fault occurring with BLOB columns and many reads. I am having a hard time diagnosing the issue. It seems to me that I may be hitting a threading bug or something. Any assistance in helping me identify the issue would be greatly appreciated.

https://gist.github.com/3955450

ruby 1.9.3p194 [x86_64-linux]
rails 3.2.8
activerecord-oracle_enhanced-adapter 1.4.1
ruby-oci8 2.1.2

Kubo Takehiro
Owner

Thank you for the dump. I reproduced the issue by the following code.
Commenting out OCILobFreeTemporary in lob.c dismisses the issue but it
will cause resource leak. It may be difficult to fix the issue.

require 'oci8'
conn = OCI8.new('ruby/oci8@//localhost/XE')

blob1 = OCI8::BLOB.new(conn, ' '  * (1024 * 1024))
blob2 = OCI8::BLOB.new(conn, ' '  * (128 * 1024 * 1024))

thr = Thread.new do
  loop do
    blob2.rewind
    blob2.read
  end
end

sleep 1
blob1 = nil  # blob1's value will be freed in GC.
sleep 10

thr.kill
conn.logoff
Kubo Takehiro
Owner

I made a patch for 2.1.2.
Download fix-issue-20.dif at https://gist.github.com/3956611

tar xvfz ruby-oci8-2.1.2.tar.gz
cd ruby-oci8-2.1.2
patch -p1 <  change-this-path/fix-issue-20.dif

Change the version number in the file ruby-oci8-2.1.2/VERSION to 2.1.2.1

gem build ruby-oci8.gemspec 
Andy Garbutt

So this patch does, indeed, suppress the seg fault. Thank you for the quick turn around. This patch seems like it could still leak memory on the server, is that correct? Let me know when you have this merged and published as a gem. Id like to deploy this and collect some more information given the additional error handling.

Kubo Takehiro
Owner

I made a patch again.
Download fix-issue-20-2.dif at https://gist.github.com/3967362

tar xvfz ruby-oci8-2.1.2.tar.gz
cd ruby-oci8-2.1.2
patch -p1 <  change-this-path/fix-issue-20-2.dif
gem build ruby-oci8.gemspec 
Kubo Takehiro
Owner

I'll release 2.1.3 next week or after next.

Kubo Takehiro kubo referenced this issue from a commit
Kubo Takehiro Fix SEGV when a temporary LOB is GCed while another LOB is read.
(github issue #20 reported by techsplicer)
2cbe227
Andy Garbutt

Thank you again for the quick turn around. Ill test this branch under some load and report back.

Andy Garbutt

So far, i have not had any issues in my test environment. However, its load is not nearly enough to test at this point. I am comfortable with this patch and waiting for the next release. If we need to re-address this, I will follow up at that point.

Kubo Takehiro kubo closed this
Kubo Takehiro
Owner

Close the issue.
If you get same problem again, create a new issue.

Edgars Beigarts

I'm still seeing segfaults with 2.1.3. I haven't found a way yet to reproduce it. Any ideas?

https://gist.github.com/583d137ab6b6ca734fab

Should I open a new ticket for this?

Kubo Takehiro
Owner

It looks same issue.
I'll reopen this.

Kubo Takehiro kubo reopened this
Kubo Takehiro kubo referenced this issue from a commit
Kubo Takehiro Fix SEGV when a temporary LOB is freed when OCILobRead returns OCI_NE…
…ED_DATA.

(github issue #20 reported by Edgars Beigarts)
719ea6f
Kubo Takehiro
Owner

I have fixed SEGV generated by the following code.

require 'oci8'
conn = OCI8.new('ruby/oci8@//localhost/XE')

blob1 = OCI8::BLOB.new(conn, ' '  * (1024 * 1024))
blob2 = OCI8::BLOB.new(conn, ' '  * (128 * 1024 * 1024))

blob1 = nil  # blob1's value will be freed in GC.
blob2.read

conn.logoff

Ebeigarts, could you try 719ea6f?

Edgars Beigarts

Thanks @kubo will try that.

Kubo Takehiro kubo closed this
Kubo Takehiro
Owner

I'll close this issue. If you get same errors, let me know.
The next version will be released this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.