-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
services/horizon/ledger: Fix memory leak in HistoryDBSource (#2548)
This commit fixes a memory leak in `HistoryDBSource.NextLedger` method. The method is usually used like in `stream_handler.go`: ``` select { case currentLedgerSequence = <-handler.LedgerSource.NextLedger(currentLedgerSequence): continue case <-ctx.Done(): stream.Done() return } ``` When streaming connection is closed but there are no new ledgers (ex. due to database or network issues) the goroutines started in `HistoryDBSource.NextLedger` will run indefinitely. To fix this `ledger.Source` interface was updated with `Close()` method that should be called when a ledger source is no longer used and it exits internal goroutine. The code was refactored to create a new `HistoryDBSource` for each streaming request (so it can be closed when handler execution ends). This should have a really minimal impact on memory usage. When there are no new ledgers, the goroutines started in `HistoryDBSource.NextLedger` will leak and will eventually consume all available memory, like in #2535.
- Loading branch information
Showing
6 changed files
with
68 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters