Skip to content

Conversation

@devmonkey22
Copy link

@devmonkey22 devmonkey22 commented Feb 3, 2020

Expected behaviour

Underlying file object should get closed when the response gets closed. The underlying StreamingHttpResponse should add the RangedFileReader to the _closable_objects list.

Actual behaviour

Without a RangedFileReader.close() method, the StreamingHttpResponse doesn't see the RangedFileReader (and its underlying file) as a closable object. The previous version also marked to close the file, but had to do it explicitly.

Description of fix

  • Added RangedFileReader.close() method, which allows underlying StreamingHttpResponse to add to _closable_objects more naturally to fix unclosed files without explicitly adding underlying file to the closable list.
  • Also initialized RangedFileReader.size using file_like.size property (if available, i.e. Django File/FieldFile) rather than reading entire file contents.

Added RangedFileReader.close() method, which allows underlying StreamingHttpResponse to add to `_closable_objects` more naturally to fix unclosed files. Also initialized `RangedFileReader.size` using `file_like.size` property (if available, i.e. Django File/FieldFile) rather than reading entire file contents.
No longer need to add file to `_closable_objects` explicitly with new reader close() method.
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.

1 participant