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

too many open files #100

Closed
mindscratch opened this issue Dec 30, 2014 · 2 comments
Closed

too many open files #100

mindscratch opened this issue Dec 30, 2014 · 2 comments
Labels

Comments

@mindscratch
Copy link

I ran into an issue where publishing messages to NSQ would eventually result in too many open files. I had code in a function that would publish a message as so:

func enqueue(queue string, message []byte) error {
  producer, err := nsq.NewProducer("...", config)
  if err != nil {
     return err
  }
  defer producer.Stop()
  err = producer.Publish(queue, message)
  return err
}

Everytime I called that function a new file descriptor (type = sock when using lsof to monitor things) was being created, that would not go away.

I moved the creation of a the producer outside the function, so the same instance would be used each time a message is published, which has "fixed" the issue. My question, I thought defer producer.Stop() would "cleanup" and thus not cause too many open files. Thoughts?

@mreiferson
Copy link
Member

Correct, you should re-use the publisher so you don't continually open new connections.

It's possible you were calling enqueue faster than the OS was reclaiming fds.

@mindscratch
Copy link
Author

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants