spring-attic/spring-social-twitter

Stream from Streaming API cannot be closed

Insferatu opened this issue · 2 comments

Each time when I try to close Stream I have the following exception

Exception in thread "Thread-11" java.lang.NullPointerException: Inflater has been closed
at java.util.zip.Inflater.ensureOpen(Inflater.java:389)
at java.util.zip.Inflater.inflate(Inflater.java:257)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:152)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:117)
at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:73)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at org.springframework.social.twitter.api.impl.StreamReaderImpl.next(StreamReaderImpl.java:59)
at org.springframework.social.twitter.api.impl.ThreadedStreamConsumer.run(ThreadedStreamConsumer.java:44)

I have same problem

Same problem in 1.1.2.RELEASE. Is there a way to close gracefully?
I dig down a bit and I think the problem is that after closing the Stream, Inputstream inside the StreamReaderImpl is null but the ThreadedStreamConsumer still try to call next() on streamReader.

I modified the org.springframework.social.twitter.api.impl.StreamReaderImpl#next:

public void next() {
		try {
			if(inputStream == null){
				throw new IOException("Input Stream closed");
			}
			String line = reader.readLine();
			if(line == null) {
				throw new IOException("Stream closed");
			}			
			queue.add(line);
		} catch (IOException e) {
			if(open.get()) {
				close();
				throw new StreamingException("The Stream is closed", e);
			}
		}
	}

I can create a PR but I see that a new version will come out.