Skip to content

Commit cc59b33

Browse files
committed
fix: drain migration channel on early return to prevent goroutine leak
runMigrations returned on the first error without draining the ret channel. The reader goroutine (read/readUp/readDown) blocked forever on a send once the PrefetchMigrations buffer filled, leaking the goroutine plus any open migration file handles or HTTP bodies. Added a deferred drain loop so the channel is fully consumed on all return paths.
1 parent 504568a commit cc59b33

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎migrate.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,12 @@ func (m *Migrate) readDown(from int, limit int, ret chan<- interface{}) {
721721
// to stop execution because it might have received a stop signal on the
722722
// GracefulStop channel.
723723
func (m *Migrate) runMigrations(ret <-chan interface{}) error {
724+
// Drain remaining items on early return so the reader goroutine can
725+
// exit and release its resources (migration file handles, HTTP bodies).
726+
defer func() {
727+
for range ret {
728+
}
729+
}()
724730
for r := range ret {
725731

726732
if m.stop() {

0 commit comments

Comments
 (0)