Charcoal-SE / metasmoke

Web dashboard for SmokeDetector.
https://metasmoke.erwaysoftware.com
Creative Commons Zero v1.0 Universal
43 stars 34 forks source link

API returns nothing even though WS says something new is created #829

Open user12986714 opened 3 years ago

user12986714 commented 3 years ago

Sometimes, after MS websocket says that a new post or a new feedback is now available, API is still returning nothing for the resource identified in WS message. I have tried to increase the delay between receiving WS message and querying API, but even at 5 seconds of delay, there are still some instances (about 3%) that API returns nothing.

This issue is also seen in Halflife. Halflife issues a message with tag [skipped] after getting nothing from MS API (search). There is an issue currently open in Halflife repository saying that Halflife is skipping too many posts. However, I think this might be a bug on MS side.

ArtOfCode- commented 3 years ago

This is just a function of the lifecycle of objects in the MS database. Websocket messages are sent based on certain events, but they can't necessarily be taken to mean "this is available right now" - they usually mean more "this is being processed now".

user12986714 commented 3 years ago

they usually mean more "this is being processed now"

This piece of information is generally not useful for applications. What applications listening to the websocket wants to know is when some resources becomes available, so they can go ahead and request for it by API. Otherwise, applications still need to fallback to polling the API for data, which defeats the whole point of metasmoke's websocket.


What looks like a bug to me is that in app/models/concerns/websocket.rb line 7 broadcast_create is added to the after_create hook, which should mean that DB transactions have finished[1]. Consequently, the object/entries in db should have already been created when broadcast_create is called. Thus, it does not seem right that API gives nothing (especially after waiting for 5 seconds).

[1]: maybe after_commit?

makyen commented 3 years ago

While I have not 100% verified it, from what I've seen, the WebSocket can and does provide, if you correctly configure your end, a complete record of the item which is being created or updated. Trying to also fetch it from the MS API is a redundant waste of bandwidth and compute capability. The WebSocket exists, not to just tell you that "this is now available for you to fetch it from the MS API", but to give you the information, so that you don't need to fetch it from the MS API.

user12986714 commented 3 years ago

but to give you the information, so that you don't need to fetch it from the MS API

That is probably true, but if one wants to get additional information they will be out of luck.

My particular use case is once a new feedback is announced by websocket, I go and fetch all feedback for the post, so that there is no need for me to keep a local db or similar in order to track all feedback for a post. With ws not synchronized with API, I often get the same list of feedback as before.