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

Update network function to use a single dispatcher and buffered channel #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kris-watts-gravwell
Copy link

@kris-watts-gravwell kris-watts-gravwell commented Aug 20, 2024

This PR does two things:

  1. Change the main Listen routine to use a single go routine with a buffered channel so that a blocked api.Writer won't build up an unlimited number of go routines eventually exhausting the stack and OOMing the process
  2. Added an optional log.Logger member to the server so that the library isn't just spitting error messages at stdout. If the logger is not specified the old behavior is maintained.

Some additional context:
RE point 1. We have found that when using the library and the current method of kicking off a go routine for every message is susceptible to stack and memory exhaustion if the api.Writer blocks for any reason. I believe that a buffered channel is a better methodology as it will eventually just block and stop consuming stack and memory space if the api.Writer cannot service the messages.

RE point 2. Errors in parsing are currently just tossed to stdout with no way for a caller to capture or route them. This just provides the option for a caller to hand in a log.Logger and route/capture those errors.

1. Change the main Listen routine to use a single go routine with a
   buffered channel so that a blocked api.Writer won't build up an
   unlimited number of go routines eventually exhausting the stack and
   OOMing the process
2. Added an optional log.Logger member to the server so that the library
   isn't just spitting error messages at stdout.  If the logger is not
   specified the old behavior is maintained.
@kris-watts-gravwell kris-watts-gravwell changed the title This PR makes a few changes to the network functionality: Update network function to use a single dispatcher and buffered channel Aug 20, 2024
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