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

Fix temp file leak druing replication error handling #1721

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

enjoy-binbin
Copy link
Member

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.

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();
Copy link
Member Author

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;
Copy link
Member Author

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);
Copy link
Member Author

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.

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 70.93%. Comparing base (2f2b8d1) to head (808bd84).

Files with missing lines Patch % Lines
src/replication.c 92.85% 1 Missing ⚠️
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     
Files with missing lines Coverage Δ
src/replication.c 87.16% <92.85%> (-0.19%) ⬇️

... and 8 files with indirect coverage changes

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.

1 participant