Skip to content

NettyTransportClient.getCurrentId is not threadsafe #1705

@John-Chan

Description

@John-Chan

Issue Description

Type: bug report

NettyTransportClient.getCurrentId

    private int getCurrentId() {
        if (idGenerator.get() > MAX_ID) {
            idGenerator.set(0);
        }
        return idGenerator.incrementAndGet();
    }

个人理解这个ID应该是用于协议纠错,getCurrentId的目的是为了循环产生ID,且在循环周期内不重复,即生成ID为1,2,3 ... -> MAX -> 1,2,3 ...

Describe what happened (or what feature you want)

当前的实现,由于MAX -> MIN 的过程不是一个原子操作,生成的ID可能会出现1,2,3 ... -> MAX -> 1,1,2,3 ...的情况。

Describe what you expected to happen

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

Anything else we need to know?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cluster-flowIssues or PRs related to cluster flow controlgood first issueGood for newcomerskind/bugCategory issues or prs related to bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions