Skip to content

When time goes back the Generate will get repeated ID. #20

Closed
@bysir-zl

Description

@bysir-zl

In line 141: if now == n.time {, I think it has a little problem:

If the time on the machine falls back(now<n.time), duplicate IDS will be generated.

The right way should be like sonyflke (https://github.com/sony/sonyflake/blob/master/sonyflake.go#L96)


This project has the most stars on github. I hope it's perfect. Haha.

Activity

bwmarrin

bwmarrin commented on Jul 30, 2019

@bwmarrin
Owner

Maybe take a look at the details in this PR :)

#18

In Go, 1.9 and later, time package uses a monotonic clock for time-measuring operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bwmarrin@bysir-zl

        Issue actions

          When time goes back the `Generate` will get repeated ID. · Issue #20 · bwmarrin/snowflake