Skip to content

fix segmentation fault when maxclients is reached - #486

Open
hotpxl wants to merge 1 commit into
yinqiwen:masterfrom
hotpxl:master
Open

fix segmentation fault when maxclients is reached#486
hotpxl wants to merge 1 commit into
yinqiwen:masterfrom
hotpxl:master

Conversation

@hotpxl

@hotpxl hotpxl commented Jun 1, 2020

Copy link
Copy Markdown

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.

1 participant