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

[Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services #3914

Closed

Conversation

Apurva007
Copy link

@Apurva007 Apurva007 commented Apr 12, 2023

Descriptions of the changes in this PR:
This PR fixes the internal server error when the following are executed with unexpected json inputs via the REST API:

  1. Trigger GC
  2. Resume Compaction
  3. Suspend Compaction
  4. Trigger Location Compaction

The reason this error occurs is because the code is trying to force cast inputs it receives as Json to Boolean without checking the type.

The code change is to make this conversion safer.

Motivation

Fixes #3845

Changes

Modified the code to perform a safer boolean conversion when trying to find the values in the JSON payload.

Master Issue: #3845

@Apurva007
Copy link
Author

Issue:
Screenshot 2023-04-12 at 12 48 10 AM

@Apurva007
Copy link
Author

Root cause:
Screenshot 2023-04-12 at 12 47 48 AM

@Apurva007
Copy link
Author

Post fix:
Screenshot 2023-04-12 at 12 49 21 AM

@Apurva007
Copy link
Author

Post Fix:
Screenshot 2023-04-12 at 12 49 30 AM

@Apurva007
Copy link
Author

Forked Repo PR where test results passed: Apurva007#1

@Apurva007
Copy link
Author

@hangc0276 / @BewareMyPower Please can you help review the PR.

Map<String, Object> configMap = JsonUtil.fromJson(requestBody, HashMap.class);
Boolean forceMajor = (Boolean) configMap.getOrDefault("forceMajor", null);
Boolean forceMinor = (Boolean) configMap.getOrDefault("forceMinor", null);
Map<String, String> configMap = JsonUtil.fromJson(requestBody, HashMap.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the requestBody doesn't pass a String, the JsonUtil.fromJson will throw an exception.
Would you please add a test for this change?

Copy link
Author

Choose a reason for hiding this comment

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

@hangc0276 Thanks for the review. I will add the respective tests.

@Apurva007 Apurva007 force-pushed the gc_internal_server_error_fix branch 6 times, most recently from bede630 to c95cc34 Compare April 18, 2023 05:13
@Apurva007 Apurva007 changed the title [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper Rest Services Apr 18, 2023
@Apurva007 Apurva007 changed the title [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper Rest Services [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services Apr 18, 2023
@Apurva007 Apurva007 force-pushed the gc_internal_server_error_fix branch from c95cc34 to 3ff05b8 Compare April 18, 2023 07:11
@Apurva007 Apurva007 force-pushed the gc_internal_server_error_fix branch from 3ff05b8 to c034c22 Compare April 18, 2023 07:14
@Apurva007
Copy link
Author

@hangc0276 I have made the suggested changes. Please can you review again when you get a chance.

@Apurva007
Copy link
Author

@hangc0276 Please can you help re-review this PR when you get a chance.

Object forceMinorObj = configMap.getOrDefault("forceMinor", null);
boolean forceMajor = false, forceMinor = false;
if (forceMajorObj instanceof Boolean) {
forceMajor = (Boolean) forceMajorObj;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should throw an error if it is not a boolean, otherwise the result is unpredictable

@Apurva007 Apurva007 closed this Sep 5, 2023
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.

Force GC API PUT Call fails with Internal Server Error
3 participants