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

Catch other exceptions from readDataset to handle file open failures #124

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

akshitamav
Copy link

readDataset throws (from HDF5) many exceptions that inherit from H5::Exception.
These exceptions should be handled and printed as a failure to open the dataset, so BAG can exit gracefully.

…en it fails to open a dataset

Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
@selimnairb
Copy link
Collaborator

@akshitamav Sorry it took me so long to get to this. Your branch inherited temporarily broken Python tests that we in the master branch, so the tests aren't currently passing. This has since been fixed in the master branch. Can you merge the latest OpenNavigationSurface:master into your branch and re-push? Thanks!

@selimnairb
Copy link
Collaborator

@akshitamav Sorry it took me so long to get to this. Your branch inherited temporarily broken Python tests that we in the master branch, so the tests aren't currently passing. This has since been fixed in the master branch. Can you merge the latest OpenNavigationSurface:master into your branch and re-push? Thanks!

@akshitamav Can you merge the latest OpenNavigationSurface:master into your branch and re-push?

@akshitamav
Copy link
Author

I have updated my branch, I think it should be right now

@akshitamav
Copy link
Author

I'm not really sure why this is failing here

@selimnairb
Copy link
Collaborator

I'm not really sure why this is failing here

The Test Reporting fails currently for pull requests since they run with read-only credentials. I thought I had fixed this last week to skip the parts that would publish the results (which requires write credentials), but apparently it needs more work. We can ignore for now.

@selimnairb
Copy link
Collaborator

@akshitamav Do you want to resolve the issue you identified here in this PR?

@akshitamav
Copy link
Author

Sure! I'm working on that right now. I'm not sure I can make it work the same way on windows (microsoft makes it work differently there) but I'm going to make it so that it also calls the "old" signal handler too so that it doesn't break other libraries signal handlers. Do we need it to work on windows as well?

@akshitamav
Copy link
Author

I added my code so far into the branch now @selimnairb, but I need to do some more testing to make sure it works. It lets people set cleanup functions, and also calls any handlers that were already set before exiting so it doesn't interfere with other libraries

@selimnairb
Copy link
Collaborator

I added my code so far into the branch now @selimnairb, but I need to do some more testing to make sure it works. It lets people set cleanup functions, and also calls any handlers that were already set before exiting so it doesn't interfere with other libraries

@akshitamav This looks like an interesting start and would cover opening BAG files using the C API (which is in the code, but not well tested currently; the preference is for people to use the C++ API). I think we would also need to add this to bagCreateFromFile, bagCreateFromBuffer. Is it necessary to have BagAbortHook in bagFileClose? My naive guess would be that BagAbortHook should be setup once (so maybe BagAbortHook needs to be a singleton?), the first time the BAG library is called, which would primarily be on opening or creating a BAG file. However, I may be mistaken.

Also, do we need to add BagAbortHook instances to BAG::Dataset::open, BAG::Dataset::create, and BAG::Metadata::loadFromFile, which are common entry-point's into the BAG library from C++ code.

@akshitamav
Copy link
Author

Ah, yeah, we should add more construction of them. I actually made it so that it unsets itself when it destructs specifically so that code that isn't bag doesn't get affected by it. It is like "take out what you take in" for camping, so someone shouldn't get the bag handler run when their other unrelated code is running.

When it returns from BAG code, it restores the original signal handlers.

I need to add it to more places to be thorough, but we should probably only add it to places where HDF5 or libxml code can run so that it isn't being used more than it needs to be.

Akshita Mavurapu added 3 commits November 24, 2024 23:23
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
@akshitamav
Copy link
Author

@selimnairb could you try starting the workflows to test the code? I think this should make it compile on windows now.

@akshitamav
Copy link
Author

@selimnairb could you try starting the workflows to test the code?

Akshita Mavurapu added 5 commits December 6, 2024 00:06
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
Signed-off-by: Akshita Mavurapu <akshitamavurapu@gmail.com>
// if the handlers are the same, don't call "bag handler" twice
char* signal_name;

#define TERM_STRING "a critical error occurred within BAG or a dependency (probably libxml or HDF5), exiting to prevent corruption or unexpected behavior\n"\
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably shouldn't put any newlines in this string since we don't know where it's going to ultimately be written to.

}

void call_cleanup_functions(int signal) {
//std::cout << "calling cleanup functions" << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove commented out code.


// if there was a handler before this, that isn't the BAG handler,
// call that one

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove blank line

this->call_previous_handler(signal);

// if nothing has exited in the previous handlers, exit here
//std::cout << "exiting" << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove commented out code


struct BagAbortHook {
BagAbortHook* previous;
//void (*old_handler[255])(int);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove commented out code

BagAbortHook* previous;
//void (*old_handler[255])(int);
//void (*current_handler[255])(int);
struct sigaction old_handlers[255];
Copy link
Collaborator

Choose a reason for hiding this comment

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

The size of these handler arrays should be a constant defined by a macro (i.e. #define somewhere).

std::cout << "made hook" << std::endl;
// set these all to null so that when restoring them
// we know which ones were added
for (int i = 0; i < 255; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use a uint8_t for looks like this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please integrate this into the C++ test suite so that it is automatically run in CI.

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.

2 participants