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

Add API to set sleep time before close. #1593

Merged
merged 2 commits into from
Aug 6, 2022
Merged

Add API to set sleep time before close. #1593

merged 2 commits into from
Aug 6, 2022

Conversation

philburk
Copy link
Collaborator

@philburk philburk commented Aug 5, 2022

Add: AudioStream::setDelayBeforeCloseMillis(delay)

This can be used to avoid use-after-free bugs
cause by callbacks running when close is called.

Fixes #1500

Add: AudioStream::setDelayBeforeCloseMillis(delay)

This can be used to avoid use-after-free bugs
cause by callbacks running when close is called.

Fixes #1500
@philburk philburk requested a review from robertwu1 August 5, 2022 00:45
Copy link
Collaborator

@robertwu1 robertwu1 left a comment

Choose a reason for hiding this comment

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

Can run some tests before/after the changes and verify that the timeout increased a lot if you call setDelayBeforeCloseMillis() on a stream? This might be messy to add as a unit test but a quick sanity check before submitting would be good.

@philburk
Copy link
Collaborator Author

philburk commented Aug 5, 2022

Can run some tests before/after the changes and verify that the timeout increased a lot if you call

"timeout"? Are you suggesting that we measure the time it takes to close a stream and assert that the time increases when we call setDelayBeforeCloseMillis() with a higher value?

@robertwu1
Copy link
Collaborator

Can run some tests before/after the changes and verify that the timeout increased a lot if you call

"timeout"? Are you suggesting that we measure the time it takes to close a stream and assert that the time increases when we call setDelayBeforeCloseMillis() with a higher value?

This test works if we set setDelayBeforeCloseMillis() to a ridiculous number like 1000ms. Otherwise, the test may be too noisy.

Alternatively, you can simply change testReturnStop.cpp locally to call setDelayBeforeCloseMillis() as a sanity check.

@philburk
Copy link
Collaborator Author

philburk commented Aug 5, 2022

I added a test that detects the increase in time required to close the stream.
The test was accurate to within a millisecond but I use a bigger tolerance.

@robertwu1
Copy link
Collaborator

I added a test that detects the increase in time required to close the stream. The test was accurate to within a millisecond but I use a bigger tolerance.

Great! Are you planning to push your test?

@philburk
Copy link
Collaborator Author

philburk commented Aug 5, 2022

Great! Are you planning to push your test?
Oops. I pushed the wrong branch.
Test now uploaded.

// Two milliseconds may be enough but 10 msec is even safer.
static constexpr int kDelayBeforeCloseMillis = 10;
public:
int32_t getMDelayBeforeCloseMillis() const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we make this uint32_t?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Google C++ style guide says:

You should not use the unsigned integer types such as uint32_t, unless there is a valid reason
such as representing a bit pattern rather than a number, or you need defined overflow
modulo 2^N. In particular, do not use unsigned types to say a number will never be negative.
Instead, use assertions for this.

Copy link
Collaborator

@robertwu1 robertwu1 left a comment

Choose a reason for hiding this comment

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

Left some minor comments. Feel free to submit either without addressing my comments or after addressing my comments.

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.

improve sleeptime between stop() and close()
2 participants