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

NullPointerException in NodeImpl#handleRequestVoteRequest #1152

Closed
alievmirza opened this issue Sep 18, 2024 · 1 comment · Fixed by #1153
Closed

NullPointerException in NodeImpl#handleRequestVoteRequest #1152

alievmirza opened this issue Sep 18, 2024 · 1 comment · Fixed by #1153

Comments

@alievmirza
Copy link
Contributor

alievmirza commented Sep 18, 2024

Describe the bug

Sometimes NPE happens in NodeImpl#handleRequestVoteRequest on the line

                final boolean logIsOk = new LogId(request.getLastLogIndex(), request.getLastLogTerm())
                    .compareTo(lastLogId) >= 0;

It happens when we call o.getTerm() in

final int c = Long.compare(getTerm(), o.getTerm());

in com.alipay.sofa.jraft.entity.LogId#compareTo, because o is null. It happens because

final LogId lastLogId = this.logManager.getLastLogId(true);

return null.

The reason of that is because when we

offerEvent(c, EventType.LAST_LOG_ID);

in com.alipay.sofa.jraft.storage.impl.LogManagerImpl#getLastLogId, we are in the situation when node is stopping, so this code is called

        if (this.stopped) {
            ThreadPoolsFactory.runClosureInThread(this.groupId, done, new Status(RaftError.ESTOP, "Log manager is stopped."));
            return;
        }

in com.alipay.sofa.jraft.storage.impl.LogManagerImpl#offerEvent. That leads to the situation that we count down latch in com.alipay.sofa.jraft.storage.impl.LogManagerImpl.LastLogIdClosure#latch, but do not set com.alipay.sofa.jraft.storage.impl.LogManagerImpl.LastLogIdClosure#lastLogId

Let's discuss a way how to fix it properly. The problem could happen everywhere when we call com.alipay.sofa.jraft.storage.impl.LogManagerImpl#getLastLogId or com.alipay.sofa.jraft.storage.impl.LogManagerImpl#getLastLogIndex(boolean)

@alievmirza
Copy link
Contributor Author

what do you think about such fix? #1153 @killme2008 @fengjiachun

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 a pull request may close this issue.

1 participant