twitter-archive / kestrel

simple, distributed message queue system (inactive)
http://twitter.github.io/kestrel
Other
2.78k stars 313 forks source link

Read-behind gets stuck (None.get) #148

Open jrray opened 9 years ago

jrray commented 9 years ago

I am encountering an issue in my application where attempting to remove an item from the queue results in a None.get, and leaves the queue in a state where all subsequent attempts to remove an item fail.

Here's the None.get:

java.util.NoSuchElementException: None.get
>.......at scala.None$.get(Option.scala:274)
>.......at scala.None$.get(Option.scala:272)
>.......at net.lag.kestrel.Journal$$anonfun$fillReadBehind$1.apply(Journal.scala:287)
>.......at net.lag.kestrel.Journal$$anonfun$fillReadBehind$1.apply(Journal.scala:265)
>.......at scala.Option.foreach(Option.scala:197)
>.......at net.lag.kestrel.Journal.fillReadBehind(Journal.scala:265)
>.......at net.lag.kestrel.PersistentQueue.fillReadBehind(PersistentQueue.scala:528)
>.......at net.lag.kestrel.PersistentQueue.net$lag$kestrel$PersistentQueue$$_remove(PersistentQueue.scala:606)
>.......at net.lag.kestrel.PersistentQueue.remove(PersistentQueue.scala:328)
>.......at net.lag.kestrel.PersistentQueue.remove(PersistentQueue.scala:349)

Looking at the code, Journal.journalAfter() is called, which returns Option[String], but the result is assumed to always be defined. readerFilename.get throws the None.get exception, and results in reader still pointing to a now-closed channel.

Subsequent remove() calls:

java.nio.channels.ClosedChannelException
>.......at sun.nio.ch.FileChannelImpl.ensureOpen(FileChannelImpl.java:99)
>.......at sun.nio.ch.FileChannelImpl.position(FileChannelImpl.java:250)
>.......at net.lag.kestrel.Journal$$anonfun$fillReadBehind$1.apply(Journal.scala:266)
>.......at net.lag.kestrel.Journal$$anonfun$fillReadBehind$1.apply(Journal.scala:265)
>.......at scala.Option.foreach(Option.scala:197)
>.......at net.lag.kestrel.Journal.fillReadBehind(Journal.scala:265)
>.......at net.lag.kestrel.PersistentQueue.fillReadBehind(PersistentQueue.scala:528)
>.......at net.lag.kestrel.PersistentQueue.net$lag$kestrel$PersistentQueue$$_remove(PersistentQueue.scala:606)
>.......at net.lag.kestrel.PersistentQueue.remove(PersistentQueue.scala:328)
>.......at net.lag.kestrel.PersistentQueue.remove(PersistentQueue.scala:349)

Unfortunately I do not know exactly how to reproduce the problem.