permitio/permit-golang

random errors

Closed this issue · 5 comments

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x10494ddc4]

goroutine 1 [running]:
github.com/permitio/permit-golang/pkg/errors.NewPermitUnexpectedError({0x0?, 0x0?})
	/Users/helloerror/go/pkg/mod/github.com/permitio/permit-golang@v0.0.3/pkg/errors/errors.go:52 +0x24
github.com/permitio/permit-golang/pkg/errors.HttpErrorHandle({0x0, 0x0}, 0x140002b6480)
	/Users/helloerror/go/pkg/mod/github.com/permitio/permit-golang@v0.0.3/pkg/errors/handlers.go:33 +0xbc
github.com/permitio/permit-golang/pkg/enforcement.(*PermitEnforcer).Check(0x1400010a460, {{0x104954767, 0xc}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...}, ...)
	/Users/helloerror/go/pkg/mod/github.com/permitio/permit-golang@v0.0.3/pkg/enforcement/check.go:87 +0xb9c
github.com/permitio/permit-golang/pkg/permit.(*Client).Check(...)
	/Users/helloerror/go/pkg/mod/github.com/permitio/permit-golang@v0.0.3/pkg/permit/permit.go:44

Hi @abhi-agridence thanks for reporting!
Can you please share an input example passed to permit.check which resulted in this error?

CC: @RazcoDev , @asafc

Hello,
We analysed the issue and found that any calls that do not complete correctly on the pdp side, result in client panics.
In above case, it seems that the container's memory configured was less, causing the request to be dropped.
Would be helpful if we can avoid a panic from code.

asafc commented

Hi @abhi-agridence thanks for reporting!

by "do not complete correctly on the pdp side", do you mean:

  • returns status code other than 200?
  • returns false (denied)?
  • PDP does not answer? (network issue)

Usually, we found these panics in scenarios -

  • misconfigured docker image
  • misconfigured CPU or memory capacity, preventing it from starting up the worker threads or it being out of memory.
    In any of these cases above, nothing valid is returned to the caller, which may be causing the panic.
    We did not check the exact response sent by the server at this instant of panic from these edge cases.

in lines -

err = NewPermitNotFoundError(err)
(L30, L33, L36) if err was sent as nil from
err = errors.HttpErrorHandle(err, res)

would cause a panic in any handlers inside https://github.com/permitio/permit-golang/blob/master/pkg/errors/handlers.go as they do a err.Error() without nil check.