Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Fix geyser plugin unload crash #34026

Merged

Conversation

lijunwangs
Copy link
Contributor

Problem

Unloading a simple plugin which does nothing other than creating the GeyserPlugin object is found to be crashing the validator. The reason for the crash is there are two objects when _drop_plugin is called: the Library object and the Box object. The current implementation drops the library first which already de-allocate the memory under the boxed GeyserPlugin. And when the GeyserPlugin is dropped, it tries to deallocate the memory and cause a segmentation fault.

Summary of Changes

Explicit ordering of the drop of Library and Box: drop the latter explicitly first.

Fixes #

Copy link

codecov bot commented Nov 12, 2023

Codecov Report

Merging #34026 (7c79f85) into master (04e4efd) will increase coverage by 0.0%.
Report is 19 commits behind head on master.
The diff coverage is 100.0%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #34026   +/-   ##
=======================================
  Coverage    81.9%    81.9%           
=======================================
  Files         811      811           
  Lines      219424   219428    +4     
=======================================
+ Hits       179761   179770    +9     
+ Misses      39663    39658    -5     

current_plugin.on_unload();
drop(current_plugin);
drop(current_lib);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure my understanding is correct, would it also resolve the crash if this line weren't here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, according to https://doc.rust-lang.org/reference/destructors.html#drop-scopes. The variables/temporaries are dropped in the reverse order of the declaration or creation. I intentionally put these explicit drop here to ensure the plugin is dropped before the library.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but the library would be dropped automatically at the end of the block.
Anyway, I don't mind the verbosity.

Copy link
Contributor

Choose a reason for hiding this comment

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

there should probably be a comment in the code that this is intentional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

current_plugin.on_unload();
drop(current_plugin);
drop(current_lib);
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but the library would be dropped automatically at the end of the block.
Anyway, I don't mind the verbosity.

@lijunwangs lijunwangs merged commit b5659af into solana-labs:master Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants