fixup! Close proxy listener if session is no longer active

pull/4850/head
Todd 2 years ago
parent 1d12242f35
commit 8fe33916c8

@ -9,7 +9,7 @@ import (
"net/netip"
"time"
"github.com/hashicorp/boundary/api/sessions"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/targets"
)
@ -38,7 +38,7 @@ type Options struct {
WithSessionAuthorizationData *targets.SessionAuthorizationData
WithSkipSessionTeardown bool
withSessionTeardownTimeout time.Duration
withSessionsClient *sessions.Client
withApiClient *api.Client
}
// Option is a function that takes in an options struct and sets values or
@ -132,10 +132,10 @@ func WithSessionTeardownTimeout(with time.Duration) Option {
}
}
// WithSessionsClient provides an optional sessions client
func WithSessionsClient(with *sessions.Client) Option {
// WithApiClient provides an optional sessions client
func WithApiClient(with *api.Client) Option {
return func(o *Options) error {
o.withSessionsClient = with
o.withApiClient = with
return nil
}
}

@ -10,7 +10,6 @@ import (
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/sessions"
"github.com/hashicorp/boundary/api/targets"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -102,12 +101,11 @@ func Test_GetOpts(t *testing.T) {
assert := assert.New(t)
opts, err := getOpts()
require.NoError(t, err)
assert.Nil(opts.withSessionsClient)
assert.Nil(opts.withApiClient)
client, err := api.NewClient(nil)
require.NoError(t, err)
sessClient := sessions.NewClient(client)
opts, err = getOpts(WithSessionsClient(sessClient))
opts, err = getOpts(WithApiClient(client))
require.NoError(t, err)
assert.Equal(sessClient, opts.withSessionsClient)
assert.Equal(client, opts.withApiClient)
})
}

@ -15,6 +15,7 @@ import (
"sync/atomic"
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/sessions"
"github.com/hashicorp/boundary/api/targets"
cleanhttp "github.com/hashicorp/go-cleanhttp"
@ -38,7 +39,7 @@ type ClientProxy struct {
connectionsLeft *atomic.Int32
connsLeftCh chan int32
callerConnectionsLeftCh chan int32
sessionsClient *sessions.Client
apiClient *api.Client
sessionAuthzData *targets.SessionAuthorizationData
createTime time.Time
expiration time.Time
@ -99,7 +100,7 @@ func New(ctx context.Context, authzToken string, opt ...Option) (*ClientProxy, e
callerConnectionsLeftCh: opts.WithConnectionsLeftCh,
started: new(atomic.Bool),
skipSessionTeardown: opts.WithSkipSessionTeardown,
sessionsClient: opts.withSessionsClient,
apiClient: opts.withApiClient,
}
if opts.WithListener != nil {
@ -263,12 +264,12 @@ func (p *ClientProxy) Start(opt ...Option) (retErr error) {
p.cancel()
return
}
if p.sessionsClient != nil {
if p.apiClient != nil {
// If we can tell that the session for the connection we just
// closed is terminated, we can close the listener, otherwise
// might as well leave it open so the next connection can be
// tried.
sess, err := p.sessionsClient.Read(p.ctx, p.sessionAuthzData.SessionId)
sess, err := sessions.NewClient(p.apiClient).Read(p.ctx, p.sessionAuthzData.SessionId)
if err != nil || sess == nil || sess.Item == nil || sess.Item.TerminationReason == "" {
return
}

Loading…
Cancel
Save