Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create close channel first inside initialize method #67

Closed
scirlig-ellation opened this issue Jan 29, 2020 · 1 comment
Closed

Create close channel first inside initialize method #67

scirlig-ellation opened this issue Jan 29, 2020 · 1 comment

Comments

@scirlig-ellation
Copy link

scirlig-ellation commented Jan 29, 2020

Background

When we start the worker by calling the Start method, the application may fail due to AWS access rights or any AWS error, in that case we retry calling start couple of times. If retrying a certain amount of times is unsuccessful we handle the error and exit our program.

However we also have a signal listener which shuts down the application gracefully, and also calls Shutdown method. Considering our workers always failed to start due to failed initialize
When the Shutdown method inside the library is called, it attempts to close stop channel which was not yet created:

worker.go#L134

close(*w.stop)

Solution

I suggest to create the stop channel & and waitGroup in the first place when calling initialize method to avoid panics when calling the Shutdown method

Here's a small example of how our Start looks like:

Start
var retries int
err := w.Start()
for err != nil && retries < app.config.Workers.MaxRetries {
	app.logger.Error(err)
	time.Sleep(5 * time.Second)
	err = w.Start()
	retries++
}
errChan <- err
@scirlig-ellation scirlig-ellation changed the title Create close channel first inside initialize method Create close channel first inside initialize method Jan 29, 2020
@taoj-action
Copy link
Contributor

We can do this by adding nil check at:
https://github.com/vmware/vmware-go-kcl/blob/master/clientlibrary/worker/worker.go#L139

	if w.done || w.stop == nil {
		return
	}

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

No branches or pull requests

2 participants