playframework / playframework/playframework
[2.4.0-M2] JsValue Websocket parseException handling issue
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 12.6k
- Forks
- 4k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 29
Description
I have a Websocket set up like this
WebSocket.tryAcceptWithActor[JsValue, JsValue] { request =>
...
}
When this receives an invalid json frame (eg {), the connection closes and a stack trace is logged to System.out
I would expect the connection to stay open and the frame to be dropped, stack traces sent to the play logger
Even better would be providing a way to handle the the invalid frame. (JsResult?)
com.fasterxml.jackson.core.JsonParseException: Unexpected end-of-input: expected close marker for OBJECT (from [Source: {; line: 1, column: 0])
at [Source: {; line: 1, column: 3]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1419)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:508)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportInvalidEOF(ParserMinimalBase.java:445)
at com.fasterxml.jackson.core.base.ParserBase._handleEOF(ParserBase.java:450)
at com.fasterxml.jackson.core.base.ParserBase._eofAsNextChar(ParserBase.java:458)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:1856)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:571)
at play.api.libs.json.JsValueDeserializer.deserialize(JsValue.scala:409)
at play.api.libs.json.JsValueDeserializer.deserialize(JsValue.scala:361)
at play.api.libs.json.JsValueDeserializer.deserialize(JsValue.scala:356)
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3038)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1652)
at play.api.libs.json.JacksonJson$.parseJsValue(JsValue.scala:488)
at play.api.libs.json.Json$.parse(Json.scala:20)
at play.api.mvc.WebSocket$FrameFormatter$$anonfun$2.apply(WebSocket.scala:80)
at play.api.mvc.WebSocket$FrameFormatter$$anonfun$2.apply(WebSocket.scala:80)
at play.core.websocket.BasicFrameFormatter$$anon$1.fromFrame(BasicFrameFormatter.scala:29)
at play.core.server.netty.WebSocketHandler$class.fromNettyFrame$1(WebSocketHandler.scala:47)
at play.core.server.netty.WebSocketHandler$$anon$1.messageReceived(WebSocketHandler.scala:103)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at com.typesafe.netty.http.pipelining.HttpPipeliningHandler.messageReceived(HttpPipeliningHandler.java:64)
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:88)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.codec.http.HttpContentDecoder.messageReceived(HttpContentDecoder.java:138)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at play.api.mvc.WebSocket.scala around the FrameFormatter code identified in the trace, then follow BasicFrameFormatter.scala and the JsValue parsing path. Reproduce an invalid JSON frame such as { and determine how the parse exception reaches the websocket handler. Done should preserve the connection, avoid printing a stack trace to System.out, and provide the requested logging or handling behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100