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

[Issue 5626][pulsar-function-go] Fix a memory leak of pulsar-function-go library regarding time.NewTimer() #5627

Merged
merged 2 commits into from
Dec 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pulsar-function-go/pf/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ func (gi *goInstance) startFunction(function function) error {
return err
}

idleDuration := getIdleTimeout(time.Millisecond * gi.context.instanceConf.killAfterIdleMs)
idleTimer := time.NewTimer(idleDuration)
defer idleTimer.Stop()

CLOSE:
for {
idleTimer.Reset(idleDuration)
select {
case cm := <-channel:
msgInput := cm.Message
Expand All @@ -94,7 +99,7 @@ CLOSE:

gi.processResult(msgInput, output)

case <-time.After(getIdleTimeout(time.Millisecond * gi.context.instanceConf.killAfterIdleMs)):
case <-idleTimer.C:
close(channel)
break CLOSE
}
Expand All @@ -107,6 +112,7 @@ CLOSE:

func (gi *goInstance) setupClient() error {
client, err := pulsar.NewClient(pulsar.ClientOptions{

URL: gi.context.instanceConf.pulsarServiceURL,
})
if err != nil {
Expand Down Expand Up @@ -271,7 +277,7 @@ func getIdleTimeout(timeoutMilliSecond time.Duration) time.Duration {
func (gi *goInstance) setupLogHandler() error {
if gi.context.instanceConf.funcDetails.GetLogTopic() != "" {
gi.context.logAppender = NewLogAppender(
gi.client, //pulsar client
gi.client, //pulsar client
gi.context.instanceConf.funcDetails.GetLogTopic(), //log topic
getDefaultSubscriptionName(gi.context.instanceConf.funcDetails.Tenant, //fqn
gi.context.instanceConf.funcDetails.Namespace,
Expand Down