-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-32228: Reset raw_pos after unwinding the raw stream #4858
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
Conversation
|
Would you add test case for it? |
…2228 Pulled from latest master
|
Thanks @methane. While writing a test case, I realised that my fix, although working, doesn't fix the root cause of the issue. Uploaded the new changes. |
|
Would you add NEWS file? |
|
Hmm, Travis doesn't work... https://travis-ci.org/python/cpython/requests |
|
@nitishch Could you close this pull request and create new one with clean git log? |
methane
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I want IO expert review if possible.
Lib/test/test_fileio.py
Outdated
| self.assertEqual(f.seek(0, io.SEEK_END), 15) | ||
| f.close() | ||
|
|
||
| f = io.open(TESTFN, 'r+b') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_fileio is specifically for FileIO tests, but you are not testing FileIO here, but BufferedIORandom. So your test should go into the relevant test class in test_io.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think the test should exercise several different buffer sizes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done for both. See if it is ok now.
| _bufferedwriter_reset_buf(self); | ||
|
|
||
| end: | ||
| _bufferedwriter_reset_buf(self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit skeptical here. Shouldn't the fix go in buffered_flush_and_rewind_unlocked instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought when we are flushing out all dirty writes, we should reset write_end. This function is called in write, seek and in flush_and_rewind. It's usage appears ok to me in all three cases.
I'm just reading through code and trying to understand the behaviour. So I might have very well misunderstood something. Please correct me in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you may well be right... I have not touched this code in a long time, so I prefer to ask.
A couple of things now:
- can you add a comment here pointing to the issue number and explaning why this is necessary?
- unrelated, but there's a comment at the beginning of
_bufferedwriter_flush_unlockedmentioningrestore_pos; that comment is obsolete, so it would be nice to remove it :-) - in
_io_BufferedWriter_write_impl, there's a fix for issue#6629which might have become unnecessary with this PR; could you check it?
pitrou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this! Buffered I/O is a delicate area. Please read the comments I left.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
@methane Since this PR has the reviews, I'll address the reviews in this branch and then create a new PR if that's ok. |
|
As an option you can rebase/squash/whatever and |
|
@nitishch And could you try log in on Travis-Ci? |
|
@pitrou I added the test for 3 buffer sizes. Please see if it is ok now. |
|
Travis build seems to be running now for some reason :) |
pitrou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the update. See comments below.
| self.assertEqual(f.read(), b"abc") | ||
|
|
||
| def test_truncate_after_write(self): | ||
| with self.open(support.TESTFN, "wb") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Can you add a comment referring to the bug entry at the beginning at the test?
| # read operation makes sure that pos != raw_pos | ||
| f.truncate() | ||
| self.assertEqual(f.tell(), buffer_size + 2) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extraneous empty line here.
| _bufferedwriter_reset_buf(self); | ||
|
|
||
| end: | ||
| _bufferedwriter_reset_buf(self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you may well be right... I have not touched this code in a long time, so I prefer to ask.
A couple of things now:
- can you add a comment here pointing to the issue number and explaning why this is necessary?
- unrelated, but there's a comment at the beginning of
_bufferedwriter_flush_unlockedmentioningrestore_pos; that comment is obsolete, so it would be nice to remove it :-) - in
_io_BufferedWriter_write_impl, there's a fix for issue#6629which might have become unnecessary with this PR; could you check it?
| @@ -0,0 +1 @@ | |||
| Reset ``write_end`` value after ``truncate()`` | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of describing the technical solution, can you describe the issue being fixed?
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
I have made the requested changes; please review again. @pitrou It seems the fix for |
|
Thanks @nitishch for the changes. The holiday period is arriving and I may not review this again before a few days. I hope you don't mind. |
|
Hi. Any updates on this? |
|
@nitishch thank you very much for doing this, and sorry for the delay. I think this PR is good to go now! |
|
@pitrou: Please replace |
|
Sorry, @nitishch and @pitrou, I could not cleanly backport this to |
|
GH-5389 is a backport of this pull request to the 3.6 branch. |
This issue was happening because - after write in the given case,
write_posandwrite_endare ending up to be 0. Nothing wrong here. But when doing truncate, we flush writer changes. During that, even whenwrite_pos == write_end, we've to resetwrite_end to -1. That was not happening.https://bugs.python.org/issue32228