Skip to content

v0.5.1

Choose a tag to compare

@dwisiswant0 dwisiswant0 released this 16 Nov 03:57
· 5 commits to master since this release
d99899e

This release fixes four bugs in saving and loading: a goroutine leak after a failed save, a hang when saving into a pipe, damaged data that reached LoadFromFunc as wrong values, and errors that errors.Is couldn't match. The exported API and the file format are unchanged: v0.5.1 writes the same bytes as v0.5.0, and each loads what the other saves.

Warning

Behavior change:

  • Loading checks the end of the saved data. LoadFrom, LoadFromFile, LoadFromFunc and LoadFromFileOrNew now read the end-of-stream chunk that minlz writes after the last entry, and reading it checks the stream's length. Data whose end chunk is missing or wrong, or that continues after the last entry, now fails to load. Before this release it loaded. Every successful save writes a valid end chunk, so only damaged or cut-off data is affected, such as a connection that closed right after the last entry. LoadFromFunc has already passed every entry to its function when it reports this error, and LoadFromFileOrNew returns an empty cache, as it does for any file it can't load. (#67, fixes #64)

Fixed

  • A failed save no longer leaves a goroutine running. The minlz writer runs a goroutine until it is closed, and saving closed it only when the save succeeded. Each SaveTo, SaveToFile, SaveToFileConcurrent or SaveToFunc whose writer failed partway, such as on a full disk or a closed connection, left one more goroutine waiting forever. (#65, fixes #61)
  • SaveTo into a pipe returns once the other end has loaded the data. LoadFrom and LoadFromFunc stopped reading at the last entry and never read the end chunk after it, so a SaveTo into an io.Pipe blocked forever writing that chunk. Loading now reads through the end chunk and stops there, without waiting for the writer to close. Because it no longer reads past the saved data, saves written one after another to the same stream also load one after another. In v0.5.0 the second load failed with minlz: corrupt input. (#67, fixes #64)
  • Damaged data no longer reaches LoadFromFunc's function as a wrong value. One damaged byte could make minlz skip a whole compressed chunk without a check. LoadFromFunc then passed the entry that spanned the gap, with different contents, and the error came only with a later entry. Loading now rejects such a chunk as minlz.ErrCorrupt as soon as it reads it, so no entry decoded across the gap is passed on. (#68, fixes #63)
  • Save and load errors wrap their cause. They kept only the text of the error that caused them, so errors.Is couldn't tell a full disk or a closed connection from damaged data. errors.Is and errors.As now match the writer's and reader's own errors, file-system errors from SaveToFile and SaveToFileConcurrent, and gob and minlz errors such as minlz.ErrCorrupt, so those errors are now part of what the functions return. Data that ends after the capacity but before all the entries it promises reports io.ErrUnexpectedEOF; only data that is empty from the start matches io.EOF. (#66, fixes #62)

Performance

  • Loading 100k entries takes the same time and memory as in v0.5.0. Saving runs the same code, apart from closing the writer on error paths.

Documentation

  • The docs for LoadFrom and LoadFromFunc now say that a successful load reads the reader to the end of the saved data and no further. (#67)

Internal

  • Loading reads through a small reader in front of minlz that ends after the end chunk and rejects chunk types that saving never writes. (#67, #68)

Full changelog: v0.5.0...v0.5.1