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

Truncate internal buffer when rows.Close() is called #904

Closed
wants to merge 2 commits into from

Conversation

methane
Copy link
Member

@methane methane commented Dec 3, 2018

Description

Fixes #903

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

@methane methane changed the title Reset internal buffer when rows.Close() is called. Truncate internal buffer when rows.Close() is called. Dec 4, 2018
@methane methane changed the title Truncate internal buffer when rows.Close() is called. Truncate internal buffer when rows.Close() is called Dec 4, 2018
Copy link

@DoctorQ DoctorQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run this changes in my project!it's ok and fixed my problem

@julienschmidt
Copy link
Member

If I understand golang/go#23519 correctly, the issue is not that buffers can not be reused at all, but that it isn't safe to do so until the next rows.Next() call.
Allocating a new buffer is a horrible bad idea and if database/sql actually would require it, then it would be horrible misdesigned.

@methane
Copy link
Member Author

methane commented Dec 4, 2018

If I understand golang/go#23519 correctly, the issue is not that buffers can not be reused at all, but that it isn't safe to do so until the next rows.Next() call.

buffer exposed by rows.Next() can't be reused from rows.Close() is called.

Allocating a new buffer is a horrible bad idea and if database/sql actually would require it, then it would be horrible misdesigned.

I agree, but this is caused by adding context support.
And #905 reduces number of allocations.

@methane
Copy link
Member Author

methane commented Jan 22, 2019

@julienschmidt Please reconsider #905 again. Currently, there is really race when context is cancelled. Race condition is one of most horrible thing in Go.

If we don't fix it soon, we should notice this bug and say "You must not cancel the context passed to
QueryContext" explicitly.

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

Successfully merging this pull request may close these issues.

3 participants