Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ LND is configured for Postgres through the following configuration options:
* `db.backend=postgres` to select the Postgres backend.
* `db.postgres.dsn=...` to set the database connection string that includes
database, user and password.
* `db.postgres.timeout=...` to set the connection timeout. If not set, no
timeout applies.
* `db.postgres.timeout` is always set to 0 (disabled). This setting is not
user-configurable as LND does not properly retry on timeout errors. Any
non-zero value will be ignored with a warning logged.

Example as follows:
```
Expand All @@ -39,8 +40,8 @@ db.backend=postgres
db.postgres.dsn=postgresql://dbuser:[email protected]:5432/dbname
db.postgres.timeout=0
```
Connection timeout is disabled, to account for situations where the database
might be slow for unexpected reasons.
Connection timeout is always disabled to prevent issues where LND would fail to
properly retry after a timeout error occurs.

Moreover for particular kv tables we also add the option to access the
tables via a global lock (single wirter). This is a temorpary measure until
Expand Down
4 changes: 2 additions & 2 deletions sample-lnd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1610,8 +1610,8 @@
; Example:
; db.postgres.dsn=postgres://lnd:lnd@localhost:45432/lnd?sslmode=disable

; Postgres connection timeout. Valid time units are {s, m, h}. Set to zero to
; disable.
; Postgres connection timeout. This setting is currently not supported and is
; always set to 0 (disabled) as LND does not properly retry on timeout errors.
; db.postgres.timeout=

; Postgres maximum number of connections. Set to zero for unlimited. It is
Expand Down
9 changes: 9 additions & 0 deletions sqldb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ func (p *PostgresConfig) Validate() error {
return fmt.Errorf("invalid DSN: %w", err)
}

// Force timeout to 0 since LND doesn't properly retry on timeout
// errors. Log a warning if the user tried to set a non-zero value.
if p.Timeout != 0 {
log.Warnf("db.postgres.timeout is not supported and will be "+
"ignored. LND does not properly retry on timeout "+
"errors, so timeout is always set to 0 (disabled).")
Comment on lines +71 to +73

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the log message is clear, its formatting can be improved to better align with the style guide, which prefers minimizing lines for log messages. You can combine the string concatenations to make this warning a two-line statement instead of three.

Suggested change
log.Warnf("db.postgres.timeout is not supported and will be "+
"ignored. LND does not properly retry on timeout "+
"errors, so timeout is always set to 0 (disabled).")
log.Warnf("db.postgres.timeout is not supported and will be "+
"ignored. LND does not properly retry on timeout errors, so "+
"timeout is always set to 0 (disabled).")
References
  1. The style guide suggests minimizing lines for log and error messages. The current implementation splits the log message string across three lines, which could be condensed to two for better readability and conciseness. (link)

p.Timeout = 0
}

if err := p.QueryConfig.Validate(false); err != nil {
return fmt.Errorf("invalid query config: %w", err)
}
Expand Down
Loading