Skip to content

Commit

Permalink
Merge pull request #3776 from telepresenceio/thallgren/goroutine-leak
Browse files Browse the repository at this point in the history
Fix goroutine leak in dialer.
  • Loading branch information
thallgren authored Jan 20, 2025
2 parents 0bee39f + 0f9d669 commit 33158d2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ items:
when creating its port-forward to the agent. The implementation could handle one such requests but not
several, resulting in a panic in situations where multiple simultaneous requests were made to the same client
during a very short time period,
- type: bugfix
title: Fix goroutine leak in dialer.
body: >-
The context passed to the `Tunnel` call that creates a stream for a dialer, was not cancelled when the dialer
was finished, so the stream was never properly closed, leading to one dormant goroutine for each stream.
- version: 2.21.1
date: 2024-12-17
notes:
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
A race could occur where several requests where made to `agentpf.client.Tunnel` on a client that had errored when creating its port-forward to the agent. The implementation could handle one such requests but not several, resulting in a panic in situations where multiple simultaneous requests were made to the same client during a very short time period,
</div>

## <div style="display:flex;"><img src="images/bugfix.png" alt="bugfix" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">Fix goroutine leak in dialer.</div></div>
<div style="margin-left: 15px">

The context passed to the `Tunnel` call that creates a stream for a dialer, was not cancelled when the dialer was finished, so the stream was never properly closed, leading to one dormant goroutine for each stream.
</div>

## Version 2.21.1 <span style="font-size: 16px;">(December 17)</span>
## <div style="display:flex;"><img src="images/bugfix.png" alt="bugfix" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">[Allow ingest of serverless deployments without specifying an inject-container-ports annotation](https://github.com/telepresenceio/telepresence/issues/3741)</div></div>
<div style="margin-left: 15px">
Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { Note, Title, Body } from '@site/src/components/ReleaseNotes'
<Title type="bugfix">Fix panic when agentpf.client creates a Tunnel</Title>
<Body>A race could occur where several requests where made to `agentpf.client.Tunnel` on a client that had errored when creating its port-forward to the agent. The implementation could handle one such requests but not several, resulting in a panic in situations where multiple simultaneous requests were made to the same client during a very short time period,</Body>
</Note>
<Note>
<Title type="bugfix">Fix goroutine leak in dialer.</Title>
<Body>The context passed to the `Tunnel` call that creates a stream for a dialer, was not cancelled when the dialer was finished, so the stream was never properly closed, leading to one dormant goroutine for each stream.</Body>
</Note>
## Version 2.21.1 <span style={{fontSize:'16px'}}>(December 17)</span>
<Note>
<Title type="bugfix" docs="https://github.com/telepresenceio/telepresence/issues/3741">Allow ingest of serverless deployments without specifying an inject-container-ports annotation</Title>
Expand Down
3 changes: 2 additions & 1 deletion pkg/tunnel/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,13 @@ func DialWaitLoop(

func dialRespond(ctx context.Context, tunnelProvider Provider, dr *rpc.DialRequest, sessionID string) {
id := ConnID(dr.ConnId)
ctx, cancel := context.WithCancel(ctx)
mt, err := tunnelProvider.Tunnel(ctx)
if err != nil {
dlog.Errorf(ctx, "!! CONN %s, call to manager Tunnel failed: %v", id, err)
cancel()
return
}
ctx, cancel := context.WithCancel(ctx)
s, err := NewClientStream(ctx, mt, id, sessionID, time.Duration(dr.RoundtripLatency), time.Duration(dr.DialTimeout))
if err != nil {
dlog.Error(ctx, err)
Expand Down

0 comments on commit 33158d2

Please sign in to comment.