ruby-rdf / sparql-client

SPARQL client for Ruby.
http://rubygems.org/gems/sparql-client
The Unlicense
112 stars 58 forks source link

EOF Error leading to segmentation fault for heavy construct queries. #79

Closed fr0gs closed 7 years ago

fr0gs commented 7 years ago

Hello,

I want to retrieve a TTL from a virtuoso endpoint.

      query(construct_query).each_statement do |statement|
        puts statement.inspect
      end

The construct query returns ~652977 statements.

CONSTRUCT {
  ?s ?p ?o
}
FROM <http://tempgraph>
WHERE {
  ?s ?p ?o .
}

But I get a segmentation fault.

/usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:209: [BUG] Segmentation fault at 0x00000000000000
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0057 p:---- s:0289 e:000288 CFUNC  :raptor_parser_parse_chunk
c:0056 p:0018 s:0282 E:001128 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:209
c:0055 p:0025 s:0278 E:001198 RESCUE /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:163
c:0054 p:0056 s:0275 E:001be0 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:157
c:0053 p:0175 s:0268 E:0006d8 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi/v2/parser.rb:92
c:0052 p:0018 s:0262 E:000110 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi.rb:118
c:0051 p:0048 s:0257 E:001290 METHOD /usr/local/bundle/gems/rdf-raptor-1.99.0/lib/rdf/raptor/ffi.rb:84
c:0050 p:0130 s:0252 E:000f38 METHOD /app/lib/queries.rb:146
... etc

However testing to query the virtuoso endpoint via HTTP directly the result is successfully fetched and created.

require 'net/http'
require 'linkeddata'
require 'cgi'

query = "CONSTRUCT { ?s ?p ?o  } FROM <http://tempgraph> WHERE { ?s ?p ?o . }"
baseURL = "http://localhost:8890/sparql/"
sparqlURL=baseURL+"?query=#{CGI.escape query}"
response = Net::HTTP.get_response(URI.parse(sparqlURL))

File.open("response.ttl", "wb") do |res|
  res.puts response.body
end                             

And it creates the full TTL

$ cat response.ttl | wc -l
652996
gkellogg commented 7 years ago

Is this not related to the separate rdf-raptor issue you filed. The only way to get Ruby to segfault otherwise is because of an interpreter bug.

fr0gs commented 7 years ago

But I have tested it manually by fetching the TTL via http, pretty much how it is done here, and then serialized the resulting file into RDF in order to verify it was successfully retrieved, and it works.

      RDF::Writer.open("/app/output.rdf") do |writer|
        RDF::Reader.open("/app/test.ttl") do |reader| # The fetched TTL calling CONSTRUCT via http.
          reader.each_statement do |statement|
            writer << statement
          end
        end
      end

It is only when calling the construct and parsing it into a series of RDF::Statement that the program segfaults.

gkellogg commented 7 years ago

But it seems to be segfaulting in Raptor. Does it segfault using a native Ruby serializer?,