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
Possible bug in fromfile with non-seekable file causing reference count error #16473
Comments
We had a couple of fixes in this area a while ago. Its possible its fixed in master. I think the only way to easily reproduce the ref-counting error is by just changing the code to always error. The decref there is correct right now, but I think the calling function had an issue thinking that it would not decref on error (but a function that steals a reference should always steal a reference, although stealing references tends to be confusing). |
Based on the comment only, it seems the intent of this function is to either:
It's possible there is a bug somewhere, but it looks to me like it would be in the caller. |
Thank you both! @seberg good point about consistency of references, I didn't think of that. I'll close this then and try to look and figure out what may have happened on the calling side. And only return when I have something reproducible :) Odds are it is indeed already fixed in master, then! |
Just to make sure you don't do double work, make sure to look at the history to see recent changes in the caller here... |
Thanks @seberg, I was going to do that. The reason I didn't look at recent changes was that the code where I suspected the bug hasn't been touched in 8-10 years. If the issue is in the caller it's a whole different kettle of fish. |
I thought I remembered something: 454c5b5 likely includes the fix for this. |
Apologies in advance for an inexact issue. I saw someone mention surprising behaviour in chat. They have fixed their original problem by updating python versions and going from 32-bit to 64-bit python, but I believe the original problem signals a bug in numpy.
The user saw this behaviour on 32-bit Python 3.7.1 (numpy version unknown) on Windows:
That refcount error raised a red flag. The binary file was 2-3 GB large. By upgrading to 64-bit Python 3.8 the original error went away. I couldn't persuade the user to investigate the original issue to see if it's present in numpy master, for instance.
I believe the problem is here:
This seems to be the exact code path that was tripped by the user. I couldn't reproduce the problem locally since
npy_fseek
calls OSfseek
directly, so I couldn't mock an object that fails to seek. However, it seems clear enough that when theIOError
is raised, wePy_DECREF
the dtype even though nothing has happened todtype
up until that point. This would explain whydtype
gets a spurious decref, eventually leading to the reference count error.My hunch is that we merely have to remove the
Py_DECREF(dtype);
line. If there's an error, we don't touch refcounts. When there's no errorPyArray_NewFromDescr
steals the reference todtype
as promised. When that fails there's noPy_INCREF
either, which is probably fine: I suspect that whenPyArray_NewFromDescr
fails then the reference is not stolen (but I couldn't figure this out either way from around here).Since I cannot reproduce the exact issue I'd rather wait for expert feedback before trying to fix the problem :)
The text was updated successfully, but these errors were encountered: