-
Notifications
You must be signed in to change notification settings - Fork 720
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.
@@ -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% 70.93% -0.04%
============================================
Files 123 123
Lines 65536 65532 -4
============================================
- Hits 46511 46488 -23
- Misses 19025 19044 +19
|
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.