awslabs / amazon-kinesis-video-streams-pic

Apache License 2.0
49 stars 47 forks source link

Add stream state machine iterator #220

Closed stefankiesz closed 11 months ago

stefankiesz commented 11 months ago

Overview

Removes the possibility of segfault errors occurring from stack overflows caused by recursive stepStateMachine() calls made internally by the stream pointer functions passed as executeStateFn to the stream state machine. Implements the following changes:

The functionality of the internal stepping of the state machine remains similar to the existing functionality, but the executeStateFn functions now set the keepIteratingStateMachine member to TRUE rather than calling stepStateMachine().

Stream State Behavior for Reference

Testing

To test these changes' success in preventing the state transition segfaults, the state machine was forced into an endless loop by commenting out the following line in fromNewStreamState():

state = STREAM_STATE_DESCRIBE;

The state machine would then endlessly transition from and to STREAM_STATE_NEW.

Without the iterator, this almost immediately caused a segfault, not even reaching 40,000 recursive calls:

Screenshot 2023-09-19 at 2 59 36 PM

Using the iterator, the sate machine continues to transition, reaching over 4 million iterations in ~1min:

Screenshot 2023-09-19 at 2 46 56 PM



By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

codecov-commenter commented 11 months ago

Codecov Report

Patch coverage: 75.00% and project coverage change: +0.04% :tada:

Comparison is base (98cc135) 75.16% compared to head (2a0a989) 75.21%.

:exclamation: Current head 2a0a989 differs from pull request most recent head 6c6993c. Consider uploading reports for the commit 6c6993c to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #220 +/- ## =========================================== + Coverage 75.16% 75.21% +0.04% =========================================== Files 52 52 Lines 10192 10203 +11 =========================================== + Hits 7661 7674 +13 + Misses 2531 2529 -2 ``` | [Files Changed](https://app.codecov.io/gh/awslabs/amazon-kinesis-video-streams-pic/pull/220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs) | Coverage Δ | | |---|---|---| | [src/client/src/Stream.c](https://app.codecov.io/gh/awslabs/amazon-kinesis-video-streams-pic/pull/220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs#diff-c3JjL2NsaWVudC9zcmMvU3RyZWFtLmM=) | `69.85% <0.00%> (ø)` | | | [src/state/src/State.c](https://app.codecov.io/gh/awslabs/amazon-kinesis-video-streams-pic/pull/220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs#diff-c3JjL3N0YXRlL3NyYy9TdGF0ZS5j) | `95.50% <ø> (ø)` | | | [src/client/src/StreamState.c](https://app.codecov.io/gh/awslabs/amazon-kinesis-video-streams-pic/pull/220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs#diff-c3JjL2NsaWVudC9zcmMvU3RyZWFtU3RhdGUuYw==) | `81.92% <84.61%> (+0.57%)` | :arrow_up: | | [src/client/src/StreamEvent.c](https://app.codecov.io/gh/awslabs/amazon-kinesis-video-streams-pic/pull/220?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs#diff-c3JjL2NsaWVudC9zcmMvU3RyZWFtRXZlbnQuYw==) | `71.50% <87.50%> (ø)` | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/awslabs/amazon-kinesis-video-streams-pic/pull/220/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=awslabs)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.