-
Notifications
You must be signed in to change notification settings - Fork 8
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
Graceful handling of incomplete streaming line data #4
Comments
Hi @fluxgain thanks for raising this. It would be interesting to find out why it happens, I mean why Oanda sends incomplete/invalid JSON strings. Could it be somehow related to the configuration of http client (spray.io)? It's easy enough to wrap the response in an Option type but would be good to understand why this happens. Any ideas? |
Yes it does feel strange that Oanda would send incomplete JSON. Perhaps it might be some intermittent internet connectivity issue. What I was not able to figure out is what happens after the bad line, does it send the rest of the line or a brand new line. In the logs it mentions unhandled events for MessageChunk after the json error and no further lines are processed. So at the moment I don't think there is enough information to get to the bottom of the issue. Perhaps with the option type and a dump of the bytes in the messagechunk that might provide more information to help solve the issue. I've attached the log file that might provide more insight. Hope this helps.
|
Hi @mslib, so I put the Option into the code as outlined above. The error did occur again, however with the Option added to the code, successive ticks now are processed correctly rather than errorring. Also when an error occurs it looks like only 1 tick has the error and it is split into 2 lines. An error with the first part of the line and the second error with the last part of the line. Below is my log snippet -
So the Option workaround limits the number of tick errors but does not help identify the root cause. |
Hi @fluxgain thanks for checking this. It might have something to do with the underlying spray http client configuration. I tried a few settings but was unable to find out what's causing it. If you can make a PR, I'll merge it into the code base and release a new version with the fix. |
Hi, I have got the same issue and it seems to be related to maximum requested characters from API. 3 trades are ok, with 4 it reach maximum for default and print on the end this:
...it will cause the crash of JSON. |
I've recently seen some errors in the streaming api with message
"unhandled event MessageChunk(Bytes(),) in state Disconnected"
where xxx is a number.
Looking at the earlier log messages this seems to have been caused by some invalid JSON trying to be parsed in my case it was - {"tick":{"instrumen . I'm guessing an incomplete line was sent from Oanda.
Looking at StreamingConnector.scala line 112 the statement line.parseJson.asJsObject.fields.head assumes the line is valid JSON in order to parse correctly. In the case it is not valid JSON an json exception is thrown in - spray.json.JsonParsersParsingException.
A possible work around may be to put a catch around line.parseJson.asJsObject.fields.head and return a Option[JSON] which could then be an additional case to match against.
Hope this all makes sense.
The text was updated successfully, but these errors were encountered: