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 segmentation fault when maxclients is reached #486

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

Conversation

hotpxl
Copy link

@hotpxl hotpxl commented Jun 1, 2020

When maxclients is reached, and another client connects,

void SocketChannel::OnAccepted()
{
    if (aeCreateFileEvent(GetService().GetRawEventLoop(), m_fd, AE_READABLE, Channel::IOEventCallback, this) == AE_ERR)
    {
        int err = errno;
        ERROR_LOG("Failed to add event for accepted client for fd:%d for reason:%s", m_fd, strerror(err));
        Close();
        return;
    }
    m_detached = false;
    m_state = SOCK_CONNECTED;
    fire_channel_open(this);
    fire_channel_connected(this);

    //INFO_LOG("Accepted on tid:%d", Thread::CurrentThreadID());
}

aeCreateFileEvent here will return AE_ERR, and Close() is immediately called. Eventually ARDB::FreeClient is called, which in turn calls UnblockKeys(ctx, true, NULL);, and we step into this function. But because a connection is never set up, ctx.client->client is a null pointer, so it'll crash with a segmentation fault. Fixing this allows connections to be closed graciously in the event maxclients is reached.

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.

None yet

1 participant