diff --git a/internal/daemon/worker/handler.go b/internal/daemon/worker/handler.go index 5b2178b9bf..52b57fa914 100644 --- a/internal/daemon/worker/handler.go +++ b/internal/daemon/worker/handler.go @@ -194,6 +194,7 @@ func (w *Worker) handleProxy(listenerCfg *listenerutil.ListenerConfig) (http.Han } return } + event.WriteSysEvent(ctx, op, "session successfully activated", "session_id", sessionId) } } @@ -234,7 +235,12 @@ func (w *Worker) handleProxy(listenerCfg *listenerutil.ListenerConfig) (http.Han } return } - defer session.CloseConnections(ctx, sessClient, w.sessionInfoMap, map[string]string{ci.Id: si.Id}) + event.WriteSysEvent(ctx, op, "connection successfully authorized", "session_id", sessionId, "connection_id", ci.Id) + defer func() { + if session.CloseConnections(ctx, sessClient, w.sessionInfoMap, map[string]string{ci.Id: si.Id}) { + event.WriteSysEvent(ctx, op, "connection closed", "session_id", sessionId, "connection_id", ci.Id) + } + }() si.Lock() ci.ConnCtx = connCtx diff --git a/internal/daemon/worker/session/session.go b/internal/daemon/worker/session/session.go index 346c9a7954..f2eed4f2a4 100644 --- a/internal/daemon/worker/session/session.go +++ b/internal/daemon/worker/session/session.go @@ -112,19 +112,20 @@ func closeConnection(ctx context.Context, sessClient pbs.SessionServiceClient, r return resp, nil } -// CloseConnections is a helper worker function that sends connection -// close requests to the controller, and sets close times within the -// worker. It is called during the worker status loop and on -// connection exit on the proxy. +// CloseConnections is a helper worker function that sends connection close +// requests to the controller, and sets close times within the worker. It is +// called during the worker status loop and on connection exit on the proxy. // -// closeInfo is a map of connections mapped to their individual -// session. -func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient, sessionInfo *sync.Map, closeInfo map[string]string) { +// The boolean indicates whether the function was successful, e.g. had any +// errors. Individual events will be sent for the errors if there are any. +// +// closeInfo is a map of connections mapped to their individual session. +func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient, sessionInfo *sync.Map, closeInfo map[string]string) bool { const op = "session.CloseConnections" if closeInfo == nil { // This should not happen, but it's a no-op if it does. Just // return. - return + return false } // How we handle close info depends on whether or not we succeeded with @@ -155,7 +156,7 @@ func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient, if err != nil { event.WriteError(ctx, op, err, event.WithInfoMsg("serious error in processing return data from controller, aborting additional session/connection state modification")) - return + return false } // Mark connections as closed @@ -164,7 +165,10 @@ func CloseConnections(ctx context.Context, sessClient pbs.SessionServiceClient, for _, err := range errs { event.WriteError(ctx, op, err, event.WithInfoMsg("error marking connection closed in state")) } + return false } + + return true } // makeCloseConnectionRequest creates a CloseConnectionRequest for diff --git a/internal/daemon/worker/status.go b/internal/daemon/worker/status.go index 9d312a6d7a..91d789214f 100644 --- a/internal/daemon/worker/status.go +++ b/internal/daemon/worker/status.go @@ -322,7 +322,7 @@ func (w *Worker) cleanupConnections(cancelCtx context.Context, ignoreSessionStat if err != nil { event.WriteError(cancelCtx, op, err, event.WithInfo("failed to create controller session client, connections won't be cleaned up")) } else { - session.CloseConnections(cancelCtx, sessClient, w.sessionInfoMap, closeInfo) + _ = session.CloseConnections(cancelCtx, sessClient, w.sessionInfoMap, closeInfo) } }