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

The cancel function created by context.WithTimeout should be called #698

Closed
fengberlin opened this issue Jul 5, 2021 · 2 comments · Fixed by #691
Closed

The cancel function created by context.WithTimeout should be called #698

fengberlin opened this issue Jul 5, 2021 · 2 comments · Fixed by #691
Labels
enhancement New feature or request

Comments

@fengberlin
Copy link
Contributor

In the latest release rocketmq-client-go sdk (version 2.1.0, the cancel function is not be called, this will cause memory/resources leak.

e.g. in the producer.go, line #244 :

ctx, _ = context.WithTimeout(ctx, 3*time.Second)

According to the go doc:

WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
Canceling this context releases resources associated with it, so code should
call cancel as soon as the operations running in this Context complete:

func slowOperationWithTimeout(ctx context.Context) (Result, error) {
 	ctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
	defer cancel()  // releases resources if slowOperation completes before timeout elapses
	return slowOperation(ctx)
}
@fengberlin
Copy link
Contributor Author

This is my PR #691

@wenfengwang
Copy link
Member

revert defer cancel() of InvokeAsync in #702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants