Git Product home page Git Product logo

Comments (7)

asterite avatar asterite commented on July 24, 2024

Thanks for reporting this!

This is for the one that's going to tackle this issue: I don't think using @io.read_fully there is the correct way to fix this, read can return less than available. However, read_fully should be used from the outside: in several places I see packet.read(some_slice) where it should be packet.read_fully(some_slice).

from crystal-mysql.

benoist avatar benoist commented on July 24, 2024

I've been trying to think what you said about the read_fully, but are you sure that's correct in this case? If I'm not mistaken the read function in ReadPacket expects the slice to be given to be of the correct size. I don't see it's being used with a buffer slice.

Perhaps you mean that the read function should be renamed read_fully as one would expect all bytes in the slice to be filled?

I would really like to know if the solution I proposed is the correct one so I can submit a pull request and close this issue and safely use the crystal-mysql shard

from crystal-mysql.

benoist avatar benoist commented on July 24, 2024

@bcardiff is anyone working on this, or can someone give me some direction on what is required to get a pull request accepted. As always I'm happy to do the work :-)

from crystal-mysql.

bcardiff avatar bcardiff commented on July 24, 2024

@benoist could you confirm that the caller to that read(slice : Bytes) is row_packet.read(@null_bitmap_slice) in https://github.com/crystal-lang/crystal-mysql/blob/master/src/mysql/result_set.cr#L54 ? If that the case, then you are probably right and a read_fully should be used.

After a bit of review I think that is the only call that may cause it.

How many columns did you need to experience this issue? Because the @null_bitmap_slice size does depends on columns but not on row.

from crystal-mysql.

benoist avatar benoist commented on July 24, 2024

I indeed traced it back to that call with the @null_bitmap_slice and suspected read_fully should have been used. However I've since refactored the code a lot whilst using the read_fully method and I'm using different columns now so I can't really try that out anymore. I forgot which columns I was using exactly and my git commits in my repo are days apart.

from crystal-mysql.

bcardiff avatar bcardiff commented on July 24, 2024

Fixed on master now. I was unable to reproduce the issue though. I tried the following spec (which I didn't commit) that inserts 2 million records of 1000 columns with just nulls.

  it "gets many columns from table" do
    with_test_db do |db|
      columns = 1000
      row = 2_000_000
      db.exec "create table table1 (#{(1..columns).map { |i| "c#{i} int null" }.join(", ")})"
      row.times do
        db.exec %(insert into table1 (c1) values (NULL))
      end

      db.query "select * from table1" do |rs|
        row.times do
          rs.move_next.should be_true
          columns.times do
            rs.read.should be_nil
          end
        end
        rs.move_next.should be_false
      end
    end
  end

Even with that I was unable to repro, but it's true that read_fully should be used to completely fill a slice from the underlying IO.

from crystal-mysql.

benoist avatar benoist commented on July 24, 2024

Great thanks!!

from crystal-mysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.