twitchscience / kinsumer

Native Go consumer for AWS Kinesis streams.
Other
134 stars 35 forks source link

Calling Stop on a stopped consumer blocks #29

Open Sytten opened 5 years ago

Sytten commented 5 years ago

The title says pretty much all. The fix is not obvious though since it is using a blocking channel internally.

garethlewin commented 5 years ago

Kinsumer is designed to be called from a single go routine, so you shouldn't have to call Stop() on a stopped consumer. That said, can you describe your use case some more, maybe I can update the library to handle your use case.

Sytten commented 5 years ago

The lib doesn't accept a Context, so it is somewhat hard to do a graceful shutdown. I ended up doing this:

go func() {
        select {
        case <-ctx.Done():
            k.Stop()
        }
    }()

But I also had a defer k.Stop() and it was blocking the shutdown.

Sytten commented 5 years ago

I guess the best way to fix this problem would be to accept a context so we can cancel the job.