langchaingo icon indicating copy to clipboard operation
langchaingo copied to clipboard

add waitgroup in ReadFromEgress function for AgentFinalStreamHandler

Open devinyf opened this issue 1 year ago • 1 comments

The ReadFromEgress function is inside a goroutine already And in some case, It's need to wait until complete from the caller So just return a waitGroup pointer that user can choose if need to use wg.Wait() or not.


PR Checklist

  • [x] Read the Contributing documentation.
  • [x] Read the Code of conduct documentation.
  • [x] Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as memory: add interfaces for X, Y or util: add whizzbang helpers).
  • [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. Fixes #123).
  • [x] Describes the source of new concepts.
  • [x] References existing implementations as appropriate.
  • [x] Contains test coverage for new functions.
  • [x] Passes all golangci-lint checks.

devinyf avatar Mar 08 '24 12:03 devinyf

update:
found that the old implementation in for xxx := range handler.egress will never end... And will cause goroutine leak fixed this problem using HandleAgentFinish method

go func() {
		defer close(handler.egress)
		for data := range handler.egress {
			callback(ctx, data)
}()

devinyf avatar Mar 09 '24 09:03 devinyf