Skip to content

proto: protect field access with lock to avoid possible data race #768

@yanke-xu

Description

@yanke-xu

Fixed inconsistency and also potential data race in proto/table_unmarshal.go:
u.reqFields is read/written 4 times in proto/table_unmarshal.go; 3 out of 4 times it is protected by u.lock.Lock(); 1 out of 4 times it is read without a Lock, which is in func unmarshal() on L260.
A data race may happen when unmarshal() and other func like computeUnmarshalInfo() are called in parallel.

In order to avoid potential data race here, I use u.lock.RLock(); defer u.lock.RUnlock() to make sure that all usages of items is in critical section.

I don't know whether it is accurate, so I 'm looking forward to your reply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions