ory / ladon

A SDK for access control policies: authorization for the microservice and IoT age. Inspired by AWS IAM policies. Written for Go.

Home Page:https://www.ory.sh/?utm_source=github&utm_medium=banner&utm_campaign=ladon

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concurrency safety

hiendaovinh opened this issue · comments

Do you want to request a feature or report a bug?
BUG

What is the current behavior?
DATA RACE

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Running IsAllowed() in multiple goroutine results in WARNING: DATA RACE

Read at 0x00c000b4c6d0 by goroutine 174:
  github.com/ory/ladon.(*Ladon).matcher()
      /go/pkg/mod/github.com/ory/ladon@v1.2.0/ladon.go:36 +0x7d5
  github.com/ory/ladon.(*Ladon).DoPoliciesAllow()
      /go/pkg/mod/github.com/ory/ladon@v1.2.0/ladon.go:82 +0x85e
  github.com/ory/ladon.(*Ladon).IsAllowed()

Previous write at 0x00c000b4c6d0 by goroutine 176:
  github.com/ory/ladon.(*Ladon).matcher()
      /go/pkg/mod/github.com/ory/ladon@v1.2.0/ladon.go:37 +0x80c
  github.com/ory/ladon.(*Ladon).DoPoliciesAllow()
      /go/pkg/mod/github.com/ory/ladon@v1.2.0/ladon.go:82 +0x85e
  github.com/ory/ladon.(*Ladon).IsAllowed()

What is the expected behavior?
It's safe to run concurrently.

Which version of the software is affected?
ory/ladon@v1.2.0

Guarding Ladon with a mutex lock could be a solution but it might affect the performance.

Nice find! A mutex sounds good