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 deputy middleware to properly close channel between connections #680

Merged
merged 1 commit into from Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions codegen/templates/tchannel_endpoint.tmpl
Expand Up @@ -244,10 +244,14 @@ func (h *{{$handlerName}}) redirectToDeputy(
"{{.ThriftService}}::{{.Name}}": "{{$methodName}}",
}

sub := h.Deps.Default.Channel.GetSubChannel(serviceName, tchannel.Isolated)
sub.Peers().Add(hostPort)
deputyChannel, err := tchannel.NewChannel(serviceName, nil)
if err != nil {
h.Deps.Default.ContextLogger.Error(ctx, "Deputy Failure", zap.Error(err))
}
defer deputyChannel.Close()
deputyChannel.Peers().Add(hostPort)
client := zanzibar.NewTChannelClientContext(
h.Deps.Default.Channel,
deputyChannel,
h.Deps.Default.Logger,
h.Deps.Default.ContextMetrics,
h.Deps.Default.ContextExtractor,
Expand All @@ -262,10 +266,6 @@ func (h *{{$handlerName}}) redirectToDeputy(
)

success, respHeaders, err := client.Call(ctx, "{{.ThriftService}}", "{{$methodName}}", reqHeaders, req, res)
// hostPort is added above, so there should not be any error returned for the
// following line
// nolint
_ = sub.Peers().Remove(hostPort)
return success, res, respHeaders, err
}
{{end -}}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.