Skip to content
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

Fix the issue of api.get_zone_status_stream not return after timeout #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

stephenli2000
Copy link

Currently, get_zone_status_stream will freeze when a video stream stops; timeout will not work. This can be reproduced if we host a stream using ffmeg/ffserver, use it as ip camera input of brainframe, and wait till the end of video file playback.

The solution implemented here is to return an empty json once we reach timeout.

brainframe/api/stubs/zone_statuses.py Outdated Show resolved Hide resolved
… the long connection alive when there is no analyzing results
int(s_id): {key: bf_codecs.ZoneStatus.from_dict(val)
for key, val in statuses.items()}
for s_id, statuses in zone_statuses_dict.items()}
processed={}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
processed={}
processed = {}

int(s_id): {key: bf_codecs.ZoneStatus.from_dict(val)
for key, val in statuses.items()}
for s_id, statuses in zone_statuses_dict.items()}
processed={}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point in yielding an empty byte. Please return the to the previous implementation (using continue), unless there was a specific reason to do this.

Copy link
Author

@stephenli2000 stephenli2000 Feb 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes the issue where the client is stuck there and never returns if a stream is gone before the client exits, the request will timeout, but API never returns. @leefrank9527

brainframe/api/stubs/zone_statuses.py Outdated Show resolved Hide resolved
@stephenli2000
Copy link
Author

There are three commits to this change. The real change is only the two lines:

                processed={}
            else:

@velovix velovix self-requested a review February 1, 2022 18:53
int(s_id): {key: bf_codecs.ZoneStatus.from_dict(val)
for key, val in statuses.items()}
for s_id, statuses in zone_statuses_dict.items()}
processed={}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change will cause downstream problems. Returning {} has semantic meaning: It means there are 0 streams.

Feel free to merge it, but consider instead raising an exception, or returning a sentinal value such as None.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apockill In some scenarios the streams will stop and be removed after running a while, so the {} is expected for these scenarios. Maybe when there are streams running, an empty string or {} will return occasionally. If so an incompatible problem may happen. Anyway, with this mechanism, the API can tell the application what happened and the application can make a decision according to the return values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants