open-traffic-generator / snappi

Open Traffic Generator SDK in Python and Go
MIT License
69 stars 7 forks source link

gosnappi `nil pointer dereference` that is coming while stopping #174

Closed alakendu closed 2 years ago

alakendu commented 2 years ago

This is the exception. Attached log for more details

panic: runtime error: invalid memory address or nil pointer dereference
    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=0xa25f19]

goroutine 34 [running]:
testing.tRunner.func1.2({0x1835b20, 0x2bee9e0})
    /usr/local/go/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
    /usr/local/go/src/testing/testing.go:1392 +0x39f
panic({0x1835b20, 0x2bee9e0})
    /usr/local/go/src/runtime/panic.go:838 +0x207
github.com/open-traffic-generator/snappi/gosnappi.(*gosnappiApi).grpcConnect(0xc0004bf880)
    /root/go/pkg/mod/github.com/open-traffic-generator/snappi/gosnappi@v0.7.37/gosnappi.go:42 +0x59
github.com/open-traffic-generator/snappi/gosnappi.(*gosnappiApi).SetCaptureState(0xc0004bf880, {0x1d77af8, 0xc000e1c088})
    /root/go/pkg/mod/github.com/open-traffic-generator/snappi/gosnappi@v0.7.37/gosnappi.go:466 +0x91
keysight/athena/tests/pkg/api.(*ApiClient).SetCaptureState(0xc0004bf8c0, {0x1d77af8, 0xc000e1c088})
    /root/tests/go/pkg/api/api.go:272 +0x213
keysight/athena/tests/pkg/api.(*ApiClient).StopCapture(0xc0004bf8c0, {0xc0004a0700, 0x1c, 0x1c})
    /root/tests/go/pkg/api/api.go:456 +0x87
keysight/athena/tests/tests.stopAndSaveCapture(0xc000531860, 0xc0008c3630?, {0x1d85650, 0xc000524000}, {0xc0004a0700?, 0x2c19b20?, 0x0?}, {0x1aeb0e6, 0x14})
    /root/tests/go/tests/gcputils.go:1097 +0x52
panic({0x1835b20, 0x2bee9e0})
    /usr/local/go/src/runtime/panic.go:838 +0x207
github.com/open-traffic-generator/snappi/gosnappi.(*gosnappiApi).grpcConnect(0xc0004bf880)
    /root/go/pkg/mod/github.com/open-traffic-generator/snappi/gosnappi@v0.7.37/gosnappi.go:42 +0x59
github.com/open-traffic-generator/snappi/gosnappi.(*gosnappiApi).SetProtocolState(0xc0004bf880, {0x1d75ef0, 0xc000e1c070})
    /root/go/pkg/mod/github.com/open-traffic-generator/snappi/gosnappi@v0.7.37/gosnappi.go:606 +0x8e
keysight/athena/tests/pkg/api.(*ApiClient).SetProtocolState(0xc0004bf8c0, {0x1d75ef0, 0xc000e1c070})
    /root/tests/go/pkg/api/api.go:214 +0x25b
keysight/athena/tests/pkg/api.(*ApiClient).StopProtocol(0xc0004bf8c0)
    /root/tests/go/pkg/api/api.go:421 +0x5c
keysight/athena/tests/tests.gcp_bgpv4_function(0xc000531860, 0x7, 0x2?, 0x64, 0xc8, 0x3e8, 0xa, {0x1ae7ee1, 0x12}, 0x0, ...)
    /root/tests/go/tests/gcp_bgpv4_function.go:405 +0x1a75
keysight/athena/tests/tests.TestScaleIxia(0x2020202020202020?)
    /root/tests/go/tests/ixia_test.go:36 +0x1b7
testing.tRunner(0xc000531860, 0x1bbf428)
    /usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
    /usr/local/go/src/testing/testing.go:1486 +0x35f
exit status 2
FAIL    keysight/athena/tests/tests 76.294s
alakendu commented 2 years ago

I think we are getting this exception due to ( within http://gitlab.it.keysight.com/athena/protocol-etoe-tests/blob/master/scripts/templates/gcp_bgpv4_function.go )

// in case of error also we must save capture
defer stopAndSaveCapture(t, client, config, capturePorts, "TestPacketCaptureDef")
defer client.StopProtocol()
defer client.Close()

As we know go multiple defer statement executes in LIFO order. So gosanppi is throwing exception when try to execute SetCaptureState after Close

Please change the code snippet to

defer client.Close()
defer client.StopProtocol()
defer stopAndSaveCapture(t, client, config, capturePorts, "TestPacketCaptureDef")