Skip to content

Potential bug of ValidContext/Valid #72

@KeiichiHirobe

Description

@KeiichiHirobe

I think there is a potential bug in current implementation of ValidContext/Valid.
When ValidContext/Valid returns true, there is a possibility that the lock is expired already.
For example, case N=5, we have 3 seconds before lock expires, even if 4 nodes responds soon(~100ms) , it is possibility that the last node needs 10 seconds to respond, and if that happens, ValidContext/Valid returns true, but lock is expired.

As far as I read https://redis.io/topics/distlock, I understand we should trust only the value of until.

If the lock was acquired, its validity time is considered to be the initial validity time minus the time elapsed, as computed in step 3.

So, if #71 merged, It may be a good idea to make ValidContext/Valid deprecated and client can check by calling Until or change implementation like below to keep backward compatibility.

func (m *Mutex) Valid() (bool, error) {
	return time.Now().Before(until), nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions