-
Notifications
You must be signed in to change notification settings - Fork 107
Exclude volatile per-request fields from Jobs crash blacklist #2673
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
Draft
MelvinBot
wants to merge
4
commits into
main
Choose a base branch
from
claude-jobsCrashBlacklistVolatileFields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1909b83
Exclude volatile per-request fields from Jobs crash blacklist
MelvinBot 6e33985
Update plugins/Jobs.cpp
cead22 b6583ab
Add unit test for Jobs crash-blacklist volatile-field exclusion
MelvinBot fc76b0d
Whitelist name and data for Jobs crash-command identifier
MelvinBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #include <libstuff/SData.h> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find this entire test quite useless. It inserts two items in a |
||
| #include <plugins/Jobs.h> | ||
| #include <test/lib/BedrockTester.h> | ||
|
|
||
| // Unit tests for BedrockJobsCommand::populateCrashIdentifyingValues(). The crash blacklist | ||
| // ("poison-pill" protection) refuses any future command whose methodLine and crashIdentifyingValues | ||
| // exactly match a command that previously crashed a node. crashIdentifyingValues is keyed on an | ||
| // explicit whitelist of the fields that semantically identify a Jobs command -- `name` and `data`. | ||
| // Everything else (e.g. `requestID`, `jobID`, `priority`, `lastIP`) is volatile or non-identifying | ||
| // per-request data. Keying only on `name`/`data` keeps the same command's repeated crashes on a | ||
| // single blacklist entry, and lets BedrockServer::_wouldCrash's "more than one identifying set -> | ||
| // block everyone" safeguard fire only when genuinely different commands crash. These tests verify | ||
| // only the whitelisted fields are kept and everything else is dropped. | ||
| struct JobsCrashIdentifyingValuesTest : tpunit::TestFixture | ||
| { | ||
| JobsCrashIdentifyingValuesTest() | ||
| : tpunit::TestFixture("JobsCrashIdentifyingValues", | ||
| TEST(JobsCrashIdentifyingValuesTest::onlyKeepsWhitelistedFields), | ||
| TEST(JobsCrashIdentifyingValuesTest::keepsOnlyPresentWhitelistedFields)) | ||
| { | ||
| } | ||
|
|
||
| // Only the whitelisted fields (`name`, `data`) and their values are kept; every other field -- | ||
| // including per-request volatile fields -- is dropped. | ||
| void onlyKeepsWhitelistedFields() | ||
| { | ||
| SData request("GetJob"); | ||
| request["name"] = "TestJob"; | ||
| request["data"] = "{\"key\":\"value\"}"; | ||
| request["jobID"] = "12345"; | ||
| request["priority"] = "500"; | ||
| request["requestID"] = "abc123"; | ||
| request["ID"] = "999"; | ||
| request["lastIP"] = "127.0.0.1"; | ||
| request["_source"] = "someSource"; | ||
|
|
||
| BedrockJobsCommand command(SQLiteCommand(move(request)), nullptr); | ||
| command.populateCrashIdentifyingValues(); | ||
|
|
||
| // Only the whitelisted fields are kept, with their original values. | ||
| ASSERT_EQUAL(command.crashIdentifyingValues.size(), 2u); | ||
| ASSERT_TRUE(command.crashIdentifyingValues.count("name")); | ||
| ASSERT_TRUE(command.crashIdentifyingValues.count("data")); | ||
| ASSERT_EQUAL(command.crashIdentifyingValues["name"], "TestJob"); | ||
| ASSERT_EQUAL(command.crashIdentifyingValues["data"], "{\"key\":\"value\"}"); | ||
|
|
||
| // Every non-whitelisted field must be excluded -- including non-volatile-but-non-identifying | ||
| // fields like jobID/priority, so the same command crashing twice stays on one blacklist entry. | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("jobID")); | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("priority")); | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("requestID")); | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("ID")); | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("lastIP")); | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("_source")); | ||
| } | ||
|
|
||
| // A whitelisted field that isn't set on the request is not recorded (CrashMap::insert skips | ||
| // fields the request doesn't have). | ||
| void keepsOnlyPresentWhitelistedFields() | ||
| { | ||
| SData request("CreateJob"); | ||
| request["name"] = "AnotherJob"; | ||
| request["priority"] = "500"; | ||
|
|
||
| BedrockJobsCommand command(SQLiteCommand(move(request)), nullptr); | ||
| command.populateCrashIdentifyingValues(); | ||
|
|
||
| // `data` was never set, so only `name` should be present; `priority` is not whitelisted. | ||
| ASSERT_EQUAL(command.crashIdentifyingValues.size(), 1u); | ||
| ASSERT_TRUE(command.crashIdentifyingValues.count("name")); | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("data")); | ||
| ASSERT_FALSE(command.crashIdentifyingValues.count("priority")); | ||
| } | ||
| } __JobsCrashIdentifyingValuesTest; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing the AI thing where it adds 50 lines to make a 3 line change, I would simply change the loop removed here with:
No changes to the .h file, -3/+2 here.