EventStore / EventStore-Client-Go

Go Client for Event Store version 20 and above.
Apache License 2.0
103 stars 25 forks source link

Nil pointer deref when reading subscription info from GRPC client #150

Closed m-guesnon-pvotal closed 10 months ago

m-guesnon-pvotal commented 11 months ago

Hi,

We've been consistently hitting this issue when using the GRPC client to read Persistent subscription info.

Client version: 3.1.0 Server version: 22.10.1

Right now, our implementation is falling back to a custom implemented HTTP client (the GRPC client seems to have a fallback mechanism to HTTP if the "feature" is not enabled, but I can't figure out how to force it to be used instead)

Stack trace

Panic: runtime error: invalid memory address or nil pointer dereferencegoroutine 1 [running]:
runtime/debug.Stack()
    /usr/local/go/src/runtime/debug/stack.go:24 +0x65
main.main.func1()
    /workspace/source/refs/heads/develop/source/gen_main.go:48 +0x3d
panic({0xf6f5c0, 0x1a373b0})
    /usr/local/go/src/runtime/panic.go:884 +0x213
github.com/EventStore/EventStore-Client-Go/v3/esdb.subscriptionInfoFromWire(0xc000ae1680)
    /workspace/source/go/pkg/mod/github.com/!event!store/!event!store-!client-!go/v3@v3.1.0/esdb/persistent_subscription_client.go:400 +0x19f
github.com/EventStore/EventStore-Client-Go/v3/esdb.(*persistentClient).getPersistentSubscriptionInfo(0xc000886970, {0x129d4a8, 0xc000a30b70}, 0x0?, 0x0?, 0xc000886a10, {0xc0006f8a80, 0x1c}, {0x129d748, 0xc000972240})
    /workspace/source/go/pkg/mod/github.com/!event!store/!event!store-!client-!go/v3@v3.1.0/esdb/persistent_subscription_client.go:298 +0x39f
github.com/EventStore/EventStore-Client-Go/v3/esdb.(*Client).getPersistentSubscriptionInfoInternal(0xc000422430, {0x129d4a8, 0xc000a30b70}, 0xc000886a10, {0xc0006f8a80, 0x1c}, {0x0, 0x0, 0x0})
    /workspace/source/go/pkg/mod/github.com/!event!store/!event!store-!client-!go/v3@v3.1.0/esdb/client.go:718 +0x21c
github.com/EventStore/EventStore-Client-Go/v3/esdb.(*Client).GetPersistentSubscriptionInfo(...)
    /workspace/source/go/pkg/mod/github.com/!event!store/!event!store-!client-!go/v3@v3.1.0/esdb/client.go:697
github.com/pvotal-tech/pvotal-x1-bp-bet_matcher/v3/internal/eventstore.(*eventStore).GetPersistentSubscriptionStats(0xc0005168a0, {0x129d4a8, 0xc000249530}, {0x110c09c, 0x7}, {0xc0006f8a80, 0x1c}, {0x0, 0x0, 0x0})
....
main.main()
    /workspace/source/refs/heads/develop/source/gen_main.go:105 +0x868

Location of the root cause:

if wire.LastCheckpointedEventPosition != "" {
    if wire.EventSource == "$all" {
        lastPos, err := parsePosition(wire.LastCheckpointedEventPosition)
        if err != nil {
            return nil, err
        }

        stats.LastCheckpointedPosition = lastPos
    } else {
        lastRev, err := parseEventRevision(wire.LastCheckpointedEventPosition)
        if err != nil {
            return nil, err
        }

        stats.LastCheckpointedEventRevision = new(uint64)
        *stats.LastKnownEventRevision = lastRev // <<< This should probably be nil checked
    }
}
YoEight commented 11 months ago

Hey @m-guesnon-pvotal and thanks for reporting this issue. While waiting for the review, could you try that patch in #151 and see if it fixes your issue?

m-guesnon-pvotal commented 10 months ago

Sorry, forgot to follow up. Thanks for the fix!