Repository navigation
v0.5.1
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,LoadFromFuncandLoadFromFileOrNewnow 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.LoadFromFunchas already passed every entry to its function when it reports this error, andLoadFromFileOrNewreturns 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,SaveToFileConcurrentorSaveToFuncwhose writer failed partway, such as on a full disk or a closed connection, left one more goroutine waiting forever. (#65, fixes #61) SaveTointo a pipe returns once the other end has loaded the data.LoadFromandLoadFromFuncstopped reading at the last entry and never read the end chunk after it, so aSaveTointo anio.Pipeblocked 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 withminlz: 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.LoadFromFuncthen 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 asminlz.ErrCorruptas 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.Iscouldn't tell a full disk or a closed connection from damaged data.errors.Isanderrors.Asnow match the writer's and reader's own errors, file-system errors fromSaveToFileandSaveToFileConcurrent, and gob and minlz errors such asminlz.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 reportsio.ErrUnexpectedEOF; only data that is empty from the start matchesio.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
LoadFromandLoadFromFuncnow 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