Skip to content
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

Compressed WARC InputStream is closed by record iterator. #93

Open
tlipkis opened this issue Apr 27, 2021 · 0 comments
Open

Compressed WARC InputStream is closed by record iterator. #93

tlipkis opened this issue Apr 27, 2021 · 0 comments

Comments

@tlipkis
Copy link

tlipkis commented Apr 27, 2021

Using the iterator obtained from a WARCReader obtained from an InputStream opened on a compressed WARC, using GZIPMembersInputStream, the InputStream is closed by the final call to hasNext(). If an uncompressed WARC is used in a similar context, the stream is not closed. The close is due to the use of SequenceInputStream in OpenJDK7GZIPInputStream (stack trace below).

(This matters to us because we maintain a use counter for each WARC in a pool, which is decremented by the close() method of a wrapper stream. The extra close causes the counter to be decremented twice. We've worked around it by wrapping the stream we pass to GZIPMembersInputStream in an IgnoreCloseInputStream (a FilterInputStream that has an empty close() method).)

We believe that open streams that are passed to library classes should not, in general, be closed by the library, and in any case the behavior should be consistent whether the WARC is compressed or not.

I'm happy to submit a PR, but I'm not certain the close performed by the SequenceInputStream is never needed. I.e., is this path ever involved in processing multiple (effectively concatenated) WARCs? My proposed fix is simply to wrap the stream ('in') passed to SequenceInputStream in an IgnoreCloseInputStream, which is inelegant but does minimal violence to the existing code.

at org.lockss.util.CloseCallbackInputStream.close(CloseCallbackInputStream.java:59)
at java.io.FilterInputStream.close(FilterInputStream.java:181)
at java.io.SequenceInputStream.nextStream(SequenceInputStream.java:106)
at java.io.SequenceInputStream.read(SequenceInputStream.java:168)
at java.util.zip.CheckedInputStream.read(CheckedInputStream.java:59)
at org.archive.util.zip.OpenJDK7GZIPInputStream.readUByte(OpenJDK7GZIPInputStream.java:268)
at org.archive.util.zip.OpenJDK7GZIPInputStream.readUShort(OpenJDK7GZIPInputStream.java:260)
at org.archive.util.zip.OpenJDK7GZIPInputStream.readHeader(OpenJDK7GZIPInputStream.java:169)
at org.archive.util.zip.GZIPMembersInputStream.readTrailer(GZIPMembersInputStream.java:138)
at org.archive.util.zip.OpenJDK7GZIPInputStream.read(OpenJDK7GZIPInputStream.java:124)
at org.archive.util.zip.GZIPMembersInputStream.read(GZIPMembersInputStream.java:113)
at org.archive.util.zip.OpenJDK7InflaterInputStream.read(OpenJDK7InflaterInputStream.java:126)
at org.lockss.laaws.rs.io.storage.warc.WarcArtifactDataStore$CompressedWARCReader.gotoEOR(WarcArtifactDataStore.java:2778)
at org.archive.io.ArchiveReader.cleanupCurrentRecord(ArchiveReader.java:176)
at org.archive.io.ArchiveReader$ArchiveRecordIterator.hasNext(ArchiveReader.java:449)

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

No branches or pull requests

1 participant