Skip to content

Conversation

@tiny-dancer
Copy link

@tiny-dancer tiny-dancer commented Sep 6, 2019

Ran into an issue in lambda where every execution after the cold start would fail due to panic: close of closed channel. Therefore leading to a 50% failure rate.

Root cause was defining the producer as a global variable outside the Handler function. This pull request assumes Start() desires idempotency. Please correct me if that is not desired and the appropriate solution is to call .New for every execution within the Handler.

kinesisProducer = producer.New(&producer.Config{
		StreamName:    kinesisStream,
		Client:        kinesisClient,
		BatchCount:    500,
		FlushInterval: 60 * time.Second,
		Logger:        &kplogrus.Logger{Logger: logs}, 
	})

func Handler(ctx context.Context, sqsEvent events.SQSEvent) error {
	kinesisProducer.Start() // <-- always fail after initial cold start

	var wg sync.WaitGroup
	wg.Add(1)

	// concurrently handle failures
	go processPutFailures(&wg)

	processSqsEvent(sqsEvent)

	kinesisProducer.Stop()

	wg.Wait()
        ...
}

@tiny-dancer tiny-dancer mentioned this pull request Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant