Skip to content

Commit

Permalink
wrapped closed context on closing sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Feb 3, 2025
1 parent 94a33dc commit 6b25d26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/query/session_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ func (core *sessionCore) deleteSession(ctx context.Context) (finalErr error) {
onDone(finalErr)
}()

if err := ctx.Err(); err != nil {
return xerrors.WithStackTrace(err)
}

if d := core.deleteTimeout; d > 0 {
var cancel context.CancelFunc
ctx, cancel = xcontext.WithTimeout(ctx, d)
Expand Down
11 changes: 10 additions & 1 deletion internal/table/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ func newTableSession( //nolint:funlen
status: table.SessionReady,
onClose: []func(s *Session) error{
func(s *Session) error {
if err := ctx.Err(); err != nil {
return xerrors.WithStackTrace(err)
}

_, err = s.client.DeleteSession(ctx,
&Ydb_Table.DeleteSessionRequest{
SessionId: s.id,
Expand Down Expand Up @@ -481,13 +485,18 @@ func (s *Session) Close(ctx context.Context) (err error) {
s.SetStatus(table.SessionClosed)
}()

errs := make([]error, 0, len(s.onClose))
for _, onClose := range s.onClose {
err := onClose(s)
if err != nil {
return xerrors.WithStackTrace(err)
errs = append(errs, err)
}
}

if len(errs) > 0 {
return xerrors.WithStackTrace(xerrors.Join(errs...))
}

return nil
}

Expand Down

0 comments on commit 6b25d26

Please sign in to comment.