Skip to content

Commit 6115f4d

Browse files
authored
fix: Prevent deadlock with database connections (#18)
An embarrassing oopsie on my part: a connection was acquired before trying to acquire a second connection, instead of after the connection had been closed.
1 parent fb3d641 commit 6115f4d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: pg.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ func NewPostgresHandlesProvider(config *pgxpool.Config, didsTable string, domain
4444
}
4545

4646
func (pg *PostgresHandles) GetDecentralizedIDForHandle(ctx context.Context, handle Handle) (DecentralizedID, error) {
47-
connection, err := pg.pool.Acquire(ctx)
48-
49-
defer connection.Release()
50-
51-
if err != nil {
52-
return "", err
53-
}
54-
5547
canProvide, err := pg.CanProvideForDomain(ctx, handle.Domain)
5648

5749
if err != nil {
@@ -62,6 +54,14 @@ func (pg *PostgresHandles) GetDecentralizedIDForHandle(ctx context.Context, hand
6254
return "", &CannotGetHandelsFromDomainError{domain: handle.Domain}
6355
}
6456

57+
connection, err := pg.pool.Acquire(ctx)
58+
59+
defer connection.Release()
60+
61+
if err != nil {
62+
return "", err
63+
}
64+
6565
var did DecentralizedID
6666

6767
query := fmt.Sprintf(

0 commit comments

Comments
 (0)