dcaoyuan/spray-websocket

infinite loop in TextFrameStream

fommil opened this issue · 1 comments

in https://github.com/wandoulabs/spray-websocket/blob/master/spray-websocket/src/main/scala/spray/can/websocket/frame/Frame.scala#L185

isn't this an infinite loop? Shouldn't the apply be adding a chunk size and using the new keyword.

object TextFrameStream {
  def apply(payload: InputStream): TextFrameStream = TextFrameStream(payload)
}

final case class TextFrameStream(chunkSize: Int, payload: InputStream) extends FrameStream {
  def opcode = Opcode.Text
}

just do this on the REPL to see

spray.can.websocket.frame.TextFrameStream(new java.io.FileInputStream("some file here"))

Yes, you're write! That clearly is an infinite recursion nobody (except us) seems to be worried of :-O

And nowhere in spray-websocket the TextFrameStream.apply() method is invoked with one argument. I can rather see TextFrameStream.apply() invoked passing 2 arguments by UHttpTest only, but that refers to the case class.

It seems the source code needs some cleanup ...