-
Notifications
You must be signed in to change notification settings - Fork 724
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
Fix temp file leak druing replication error handling #1721
base: unstable
Are you sure you want to change the base?
Conversation
Before actually entering REPL_STATE_TRANSFER, we usually have some other things to do, such as registering the ae handler, etc. If an error occurs at this time, we may leak the previously opened temp file. This commit adds a new cleanupTransferResources function to do the cleanup, avoiding code duplication. Signed-off-by: Binbin <[email protected]>
@@ -2871,8 +2867,7 @@ static void dualChannelFullSyncWithPrimary(connection *conn) { | |||
connClose(server.repl_rdb_transfer_s); | |||
server.repl_rdb_transfer_s = NULL; | |||
} | |||
if (server.repl_transfer_fd != -1) close(server.repl_transfer_fd); | |||
server.repl_transfer_fd = -1; | |||
cleanupTransferResources(); | |||
server.repl_state = REPL_STATE_CONNECT; | |||
replicationAbortDualChannelSyncTransfer(); |
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.
replicationAbortDualChannelSyncTransfer also some cleanups, like replicationAbortDualChannelSyncTransfer will close repl_rdb_transfer_s and repl_transfer_fd. We can remove it in here. Please let me know if you want it removed.
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.
I think we should call cleanupTransferResources
from replicationAbortDualChannelSyncTransfer
to maintain consistency in our error handling.
We should also consider modifying replicationAbortSyncTransfer
to handle the cleanup of temporary RDB file resources even when the replication state is not REPL_STATE_TRANSFER
.
src/replication.c
Outdated
@@ -2871,8 +2867,7 @@ static void dualChannelFullSyncWithPrimary(connection *conn) { | |||
connClose(server.repl_rdb_transfer_s); | |||
server.repl_rdb_transfer_s = NULL; |
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.
the leak may happen in here, we should also unlink the tmp file
@@ -3856,10 +3852,7 @@ void syncWithPrimary(connection *conn) { | |||
connClose(server.repl_rdb_transfer_s); | |||
server.repl_rdb_transfer_s = NULL; | |||
} | |||
if (server.repl_transfer_fd != -1) close(server.repl_transfer_fd); | |||
if (server.repl_transfer_tmpfile) zfree(server.repl_transfer_tmpfile); |
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.
the leak may happen in here, we should also unlink the tmp file.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #1721 +/- ##
============================================
+ Coverage 70.97% 71.12% +0.15%
============================================
Files 123 123
Lines 65536 65522 -14
============================================
+ Hits 46511 46602 +91
+ Misses 19025 18920 -105
|
Signed-off-by: Binbin <[email protected]>
src/replication.c
Outdated
@@ -3850,16 +3842,11 @@ void syncWithPrimary(connection *conn) { | |||
/* Fall through to regular error handling */ | |||
|
|||
error: | |||
connClose(conn); | |||
server.repl_transfer_s = NULL; |
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.
remove this since replicationAbortSyncTransfer will handle this as well
@@ -2867,14 +2864,8 @@ static void dualChannelFullSyncWithPrimary(connection *conn) { | |||
connClose(server.repl_transfer_s); | |||
server.repl_transfer_s = NULL; | |||
} | |||
if (server.repl_rdb_transfer_s) { |
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.
remove this since replicationAbortDualChannelSyncTransfer will handle it as well
Signed-off-by: Binbin <[email protected]>
Co-authored-by: Amit Nagler <[email protected]> Signed-off-by: Binbin <[email protected]>
Before actually entering REPL_STATE_TRANSFER, we usually have
some other things to do, such as registering the ae handler, etc.
If an error occurs at this time, we may leak the previously opened
temp file.
This commit adds a new cleanupTransferResources function to do the
cleanup, avoiding code duplication.