Skip to content

Data race when simultaneous POSTs to /services/haproxy/runtime/maps/{parent_name}/entries with same key #137

@kevinchannon

Description

@kevinchannon

Raising this issue in this repo, because it's where I think the issue is. I actually see it when using the Dataplane API though.

Entries are (I think) added to the mapping in this function (in runtime/maps.go):

// AddMapEntry adds an entry into the map file
func (s *SingleRuntime) AddMapEntry(name, key, value string) error {
	m, _ := s.GetMapEntry(name, key)
	if m != nil {
		return fmt.Errorf("%w", native_errors.ErrAlreadyExists)
	}
	cmd := fmt.Sprintf("add map %s %s %s", name, key, value)
	if err := s.Execute(cmd); err != nil {
		return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral)
	}
	return nil
}

I can't see that there is any locking in this function that prevents a second call to it from doing s.GetMapEntry(name, key) while a previous call is between that line and the eventual s.Execute(cmd); line. In this case (and in fact in my case, where I'm spamming a lot of POSTs at the /services/haproxy/runtime/maps/{parent_name}/entries with the same key and waiting to find out which is the winner) the last one through will win and the first mapping will be silently lost.

I'm not a Golang expert though, so the actual locking could be somewhere else (and I see my map getting messed up for some other reason).

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