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

[cmd] Fix RepeatCommand calling end() twice #5261

Merged
merged 5 commits into from
Apr 29, 2023

Conversation

KangarooKoala
Copy link
Contributor

If the command wrapped by a RepeatCommand finished naturally at the same time the repeat command was interrupted, .end() would be called twice (first .end(false) and then .end(true)).
This was especially problematic if the wrapped command is a ProxyCommand, since the first call to .end() would set its m_command to null and then the second call would attempt to call m_command.cancel(), resulting in a NPE.

@KangarooKoala KangarooKoala requested a review from a team as a code owner April 12, 2023 02:22
@KangarooKoala
Copy link
Contributor Author

Should we add tests for this behavior?

@Starlight220
Copy link
Member

Starlight220 commented Apr 13, 2023

If the command wrapped by a RepeatCommand finished naturally at the same time the repeat command was interrupted

How would this happen?
You're right, due to #4706 the wrapped command is in an inactive state between finishing and RepeatCommand's next iteration, and thus calling end twice is UB.
This patch does indeed fix the issue; just add an explanatory comment and tests.

@Starlight220 Starlight220 self-requested a review April 13, 2023 09:51
@KangarooKoala
Copy link
Contributor Author

#4576 is about PS4 triangle methods, did you mean a different PR?
Regardless, I added the comment and the tests, which hopefully help explain how this can happen.

@Starlight220
Copy link
Member

My mistake, I meant #4706.

@KangarooKoala
Copy link
Contributor Author

There's a few other tests that use CommandScheduler.getInstance() instead of new CommandScheduler() in the try-with-resources, should I fix those as well in here or in a separate PR?

@Starlight220
Copy link
Member

Don't fix them here.

@KangarooKoala
Copy link
Contributor Author

Okay, any other changes to make?

Starlight220
Starlight220 previously approved these changes Apr 14, 2023
Copy link
Member

@Starlight220 Starlight220 left a comment

Choose a reason for hiding this comment

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

(Assuming CI passes)
Looks good to me

@KangarooKoala
Copy link
Contributor Author

image

This is what failed, and it doesn't seem to be related to this PR?

@KangarooKoala
Copy link
Contributor Author

CI passes

@PeterJohnson PeterJohnson merged commit 40ca094 into wpilibsuite:main Apr 29, 2023
@KangarooKoala KangarooKoala deleted the fixDoubleEnd branch April 29, 2023 18:56
This pull request was closed.
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.

3 participants