Skip to content

Commit 4c12f4a

Browse files
watchCtx
1 parent c5bcb34 commit 4c12f4a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ on:
44
push:
55
branches:
66
- "main"
7+
- "debug"
78
pull_request:
89
branches:
910
- "**"
1011
workflow_dispatch:
1112

1213
jobs:
1314
tests:
15+
if: false
1416
name: Tests
1517
runs-on: ubuntu-latest
1618
services:

storage.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,28 @@ func (s *PostgresStorage) ensureTableExists(ctx context.Context) error {
154154
return err
155155
}
156156

157+
func watchCtx(ctx context.Context, kind, name string, log *zap.Logger) {
158+
go func() {
159+
<-ctx.Done()
160+
// Go 1.20+: context.Cause gives you the *reason* (deadline, cancel, or custom)
161+
err := context.Cause(ctx)
162+
if err == nil {
163+
err = ctx.Err()
164+
} // fallback
165+
if dl, ok := ctx.Deadline(); ok {
166+
log.Debug("ctx done", zap.String("kind", kind), zap.String("name", name),
167+
zap.Error(err), zap.Time("deadline", dl), zap.Duration("until_deadline", time.Until(dl)))
168+
} else {
169+
log.Debug("ctx done", zap.String("kind", kind), zap.String("name", name), zap.Error(err))
170+
}
171+
}()
172+
}
173+
157174
func (s *PostgresStorage) Lock(ctx context.Context, name string) error {
158175
s.logger.Debug("acquiring lock", zap.String("name", name))
159176

177+
watchCtx(ctx, "acquire", name, s.logger)
178+
160179
lock, err := s.pglock.AcquireContext(ctx, name)
161180
if err != nil {
162181
return fmt.Errorf("could not acquire pglock: %w", err)

0 commit comments

Comments
 (0)