Skip to content

Commit 698ccfe

Browse files
committed
fix: recover an asynchronouse closing timing issue go-ldap#319
1 parent 51a1a4f commit 698ccfe

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

search.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,13 @@ func (l *Conn) SearchWithChannel(ctx context.Context, searchRequest *SearchReque
595595
ch = make(chan *SearchSingleResult)
596596
}
597597
go func() {
598-
defer close(ch)
598+
defer func() {
599+
close(ch)
600+
if err := recover(); err != nil {
601+
l.err = fmt.Errorf("ldap: recovered panic in SearchWithChannel: %v", err)
602+
}
603+
}()
604+
599605
if l.IsClosing() {
600606
return
601607
}

v3/search.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,13 @@ func (l *Conn) SearchWithChannel(ctx context.Context, searchRequest *SearchReque
597597
ch = make(chan *SearchSingleResult)
598598
}
599599
go func() {
600-
defer close(ch)
600+
defer func() {
601+
close(ch)
602+
if err := recover(); err != nil {
603+
l.err = fmt.Errorf("ldap: recovered panic in SearchWithChannel: %v", err)
604+
}
605+
}()
606+
601607
if l.IsClosing() {
602608
return
603609
}

0 commit comments

Comments
 (0)