|
99 | 99 | keyLength = 33 |
100 | 100 | ) |
101 | 101 |
|
102 | | -// DefaultLoopOutHtlcConfirmations is the default number of confirmations we |
103 | | -// set for a loop out htlc. |
104 | | -const DefaultLoopOutHtlcConfirmations uint32 = 1 |
| 102 | +const ( |
| 103 | + // DefaultLoopOutHtlcConfirmations is the default number of |
| 104 | + // confirmations we set for a loop out htlc. |
| 105 | + DefaultLoopOutHtlcConfirmations uint32 = 1 |
| 106 | + |
| 107 | + // DefaultLoopDBTimeout is the default maximum time we wait for the |
| 108 | + // Loop bbolt database to be opened. If the database is already opened |
| 109 | + // by another process, the unique lock cannot be obtained. With the |
| 110 | + // timeout we error out after the given time instead of just blocking |
| 111 | + // for forever. |
| 112 | + DefaultLoopDBTimeout = 5 * time.Second |
| 113 | +) |
105 | 114 |
|
106 | 115 | // fileExists returns true if the file exists, and false otherwise. |
107 | 116 | func fileExists(path string) bool { |
@@ -139,7 +148,14 @@ func NewBoltSwapStore(dbPath string, chainParams *chaincfg.Params) ( |
139 | 148 | // Now that we know that path exists, we'll open up bolt, which |
140 | 149 | // implements our default swap store. |
141 | 150 | path := filepath.Join(dbPath, dbFileName) |
142 | | - bdb, err := bbolt.Open(path, 0600, nil) |
| 151 | + bdb, err := bbolt.Open(path, 0600, &bbolt.Options{ |
| 152 | + Timeout: DefaultLoopDBTimeout, |
| 153 | + }) |
| 154 | + if err == bbolt.ErrTimeout { |
| 155 | + return nil, fmt.Errorf("%w: couldn't obtain exclusive lock on "+ |
| 156 | + "%s, timed out after %v", bbolt.ErrTimeout, path, |
| 157 | + DefaultLoopDBTimeout) |
| 158 | + } |
143 | 159 | if err != nil { |
144 | 160 | return nil, err |
145 | 161 | } |
|
0 commit comments