fluxcd / notification-controller

The GitOps Toolkit event forwarded and notification dispatcher

Home Page:https://fluxcd.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic while using bitbucketserver provider for git commit status

gdasson opened this issue · comments

Describe the bug

The support for Bitbucket Server/Datacenter as a provider for git commit status was introduced by this PR

Unfortunately, while testing the code using self signed certificates, I noticed a bug in the code that's causing a panic: runtime error: invalid memory address or nil pointer dereference error

To Reproduce:

Steps to reproduce the behavior:

  1. Enable bitbucket server provider for git commit status like below:
apiVersion: notification.toolkit.fluxcd.io/v1beta3
kind: Provider
metadata:
  name: server-commit-status-provider
  namespace: flux-system
spec:
  address: https://test.internal.server:8443/scm/foo/bar.git
  secretRef:
    name: token
  type: bitbucketserver
  1. The certificate for the server is self signed, but certSecretRef was not provided

Current Actual behavior:

Notification controller dies with a panic error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1659578]

goroutine 236 [running]:
github.com/fluxcd/notification-controller/internal/notifier.BitbucketServer.duplicateBitbucketServerStatus({{0x40007d3766, 0x5}, {0x40007d376c, 0xd}, {0x40006db680, 0x24}, {0x40007d3740, 0x3d}, {0x400071cb70, 0x21}, ...}, ...)
	github.com/fluxcd/notification-controller/internal/notifier/bitbucketserver.go:195 +0x258
github.com/fluxcd/notification-controller/internal/notifier.BitbucketServer.Post({{0x40007d3766, 0x5}, {0x40007d376c, 0xd}, {0x40006db680, 0x24}, {0x40007d3740, 0x3d}, {0x400071cb70, 0x21}, ...}, ...)
	github.com/fluxcd/notification-controller/internal/notifier/bitbucketserver.go:155 +0x3a8
github.com/fluxcd/notification-controller/internal/server.(*EventServer).dispatchNotification.func1({0x2008500, 0x4000523e60}, {{{0x40007c6870, 0xd}, {0x40007c6880, 0xb}, {0x40007be588, 0x18}, {0x40006daf60, 0x24}, ...}, ...})
	github.com/fluxcd/notification-controller/internal/server/event_handlers.go:210 +0xc0
created by github.com/fluxcd/notification-controller/internal/server.(*EventServer).dispatchNotification in goroutine 234
	github.com/fluxcd/notification-controller/internal/server/event_handlers.go:207 +0x1d0

Expected behavior:

Notification controller should handle the issue gracefully and emit an error message in its logs

Current workaround:

Please make sure to specify certSecretRef (a valid CA cert) to trust the self signed cert

Can you please post here the whole message including the stack trace.

@stefanprodan : Sure, will do that. I am already testing the fix for it in my env and will soon be submitting a PR to close this issue, since I was the author of that initial PR that introduced this functionality. I just reported this issue for awareness.

@stefanprodan : Edited the original issue text above to show error with stack trace. I have submitted a PR to fix this bug and added more enhancements.