Skip to content

Commit

Permalink
Force flush buffer to avoid data corruption (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidy1991 committed Feb 22, 2022
1 parent dbb675d commit 023a778
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions jupyter_archive/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def handler_max_buffer_length(self):
def archive_download_flush_delay(self):
return self.settings["jupyter_archive"].archive_download_flush_delay

def flush(self, include_footers=False):
def flush(self, include_footers=False, force=False):
# skip flush when stream_buffer is larger than stream_max_buffer_size
stream_buffer = self.request.connection.stream._write_buffer
if stream_buffer and len(stream_buffer) > self.stream_max_buffer_size:
if not force and stream_buffer and len(stream_buffer) > self.stream_max_buffer_size:
return
return super(DownloadArchiveHandler, self).flush(include_footers)

Expand Down Expand Up @@ -166,7 +166,8 @@ async def get(self, archive_path, include_body=False):
if self.canceled:
self.log.info("Download canceled.")
else:
self.flush()
# Here, we need to flush forcibly to move all data from _write_buffer to stream._write_buffer
self.flush(force=True)
self.log.info("Finished downloading {}.".format(archive_filename))

self.set_cookie("archiveToken", archive_token)
Expand Down

0 comments on commit 023a778

Please sign in to comment.