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 TCPSocket constructor exception safety #112

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

Conversation

tsr-boxbot
Copy link
Contributor

This commit fixes closing a TCPSocket's raw socket if something goes wrong in the constructor. Presently if the socket gets opened but something else goes wrong then the file descriptor(FD) is left dangling and can quickly exhaust the system FD limit

This commit fixes closing a TCPSocket's raw socket if something goes
wrong in the constructor. Presently if the socket gets opened but
something else goes wrong then the file descriptor(FD) is left
dangling and can quickly exhaust the system FD limit
socket_->Close();
}
}
void do_not_cleanup() {
Copy link

Choose a reason for hiding this comment

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

This is not called anywhere, which means the file descriptor is always cleaned up after the constructor is finished

socket_scope_cleanup(TCPSocket* socket):socket_(socket){}
~socket_scope_cleanup() {
if(should_cleanup) {
Logger(LogLevel::DEBUG) << "Close TCP socket fd=" << _sockedFd;
Copy link

Choose a reason for hiding this comment

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

Suggested change
Logger(LogLevel::DEBUG) << "Close TCP socket fd=" << _sockedFd;
Logger(LogLevel::DEBUG) << "Close TCP socket fd=" << socket_->_sockedFd;

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