vapor-ware / synse-sdk

SDK for Synse Plugins in Go
https://synse.readthedocs.io/en/latest/sdk/intro/
GNU General Public License v3.0
3 stars 4 forks source link

NewTransaction() invalid memory address or nil pointer dereference #131

Closed MatthewHink closed 6 years ago

MatthewHink commented 6 years ago

I only see this when running the transaction_test.go file independently.

When all tests are run, some previously run test must have initialized it by creating a Plugin.

Root cause is that NewTransaction() does not initialize the transactionCache global, but it's used in NewTransaction here:

transactionCache.Set(id, &transaction, cache.DefaultExpiration)

Repro:

[mhink@ion ~/go/src/github.com/vapor-ware/synse-sdk (master)]$ git branch | grep master
* master
[mhink@ion ~/go/src/github.com/vapor-ware/synse-sdk (master)]$ git log -n 1 --pretty=oneline
8f6482c59f005c8f632600ad995bc51ee7e40aea (HEAD -> master, origin/master, origin/HEAD, mhink-trans-cache) Merge pull request #128 from vapor-ware/mhink-parameter-tests-data-manager
[mhink@ion ~/go/src/github.com/vapor-ware/synse-sdk (master)]$ make clean
go clean -v
[mhink@ion ~/go/src/github.com/vapor-ware/synse-sdk (master)]$ go test -cover sdk/transaction_test.go sdk/constants.go sdk/data_manager.go sdk/devices.go sdk/doc.go sdk/errors.go sdk/handlers.go sdk/models.go sdk/plugin.go sdk/server.go sdk/transaction.go sdk/utils.go sdk/validate.go sdk/version.go
--- FAIL: TestNewTransaction (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x14c6978]

goroutine 5 [running]:
testing.tRunner.func1(0xc4201522d0)
    /usr/local/opt/go/libexec/src/testing/testing.go:711 +0x2d2
panic(0x155d340, 0x1926840)
    /usr/local/opt/go/libexec/src/runtime/panic.go:491 +0x283
command-line-arguments.NewTransaction(0x30)
    command-line-arguments/_test/_obj_test/transaction.go:43 +0x148
command-line-arguments.TestNewTransaction(0xc4201522d0)
    /Users/mhink/go/src/github.com/vapor-ware/synse-sdk/sdk/transaction_test.go:9 +0x34
testing.tRunner(0xc4201522d0, 0x1625d20)
    /usr/local/opt/go/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
    /usr/local/opt/go/libexec/src/testing/testing.go:789 +0x2de
FAIL    command-line-arguments  0.023s
[mhink@ion ~/go/src/github.com/vapor-ware/synse-sdk (master)]$
MatthewHink commented 6 years ago

Fixed: https://github.com/vapor-ware/synse-sdk/commit/7a0452f14319db5e52530122f14ab3c5de09a374