tyk icon indicating copy to clipboard operation
tyk copied to clipboard

Fix pointer error

Open PericlesTheo opened this issue 2 years ago • 1 comments

Description

logrus_sentry.NewSentryHook returns a pointer to a SentryHook. Simply passing a malformed DSN will result in SentryHook being nil which we then call hook.Timeout resulting in a pointer dereference error

Related Issue

No issue created

How This Has Been Tested

I am not sure how this can be tested unfortunately. Happy to be pointed in the right direction.

Screenshots (if appropriate)

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • [x] Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If pulling from your own fork, don't request your master!
  • [x] Make sure you are making a pull request against the master branch (left side). Also, you should start your branch off our latest master.
  • [ ] My change requires a change to the documentation.
    • [ ] If you've changed APIs, describe what needs to be updated in the documentation.
    • [ ] If new config option added, ensure that it can be set via ENV variable
  • [ ] I have updated the documentation accordingly.
  • [ ] Modules and vendor dependencies have been updated; run go mod tidy && go mod vendor
  • [ ] When updating library version must provide reason/explanation for this update.
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.
  • [ ] Check your code additions will not fail linting checks:
    • [ ] go fmt -s
    • [ ] go vet

PericlesTheo avatar Sep 07 '22 14:09 PericlesTheo

also I am thinking the debug log about the sentry hook being active should not appear if there is an issue. so something like

hook, err := logrus_sentry.NewSentryHook(gwConfig.SentryCode, logLevel)
if err != nil {
    mainLog.Debug(fmt.Sprintf("Sentry hook not error=%s", err.Error())
}

if err == nil {
    hook.Timeout = 0
    log.Hooks.Add(hook)
    rawLog.Hooks.Add(hook)
    mainLog.Debug("Sentry hook active")
}

PericlesTheo avatar Sep 08 '22 08:09 PericlesTheo

@PericlesTheo thanks for the contribution, we brought this change to our and internal process and we'll be releasing this change in the following patches.

lghiur avatar Nov 25 '22 11:11 lghiur

/release to release-4

titpetric avatar Dec 05 '22 12:12 titpetric

Working on it! Note that it can take a few minutes.

tykbot[bot] avatar Dec 05 '22 12:12 tykbot[bot]

@titpetric Succesfully merged PR

tykbot[bot] avatar Dec 05 '22 12:12 tykbot[bot]

API tests result: success :white_check_mark: Branch used: refs/heads/master Commit: 1beafa0699c292eda397f3f23eb5fd44071b9030 TT-7124 Fix pointer error (#4291)

logrus_sentry.NewSentryHook returns a pointer to a SentryHook. Simply passing a malformed DSN will result in SentryHook being nil which we then call hook.Timeout resulting in a pointer dereference error Triggered by: push (@titpetric) Execution page

Tyk-ITS avatar Dec 05 '22 12:12 Tyk-ITS

/release to release-4-lts

titpetric avatar Dec 05 '22 15:12 titpetric

Working on it! Note that it can take a few minutes.

tykbot[bot] avatar Dec 05 '22 15:12 tykbot[bot]

@titpetric Succesfully merged PR

tykbot[bot] avatar Dec 05 '22 15:12 tykbot[bot]