Skip to content

Commit 21b0e7c

Browse files
committed
oc adm groups sync: Use client.Unbind
This is a bit nicer than client.Close, it's a polite quit.
1 parent d07df3d commit 21b0e7c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/cli/admin/groups/sync/prune.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ func (o *PruneOptions) Run() error {
168168
if err != nil {
169169
return err
170170
}
171-
defer ldapClient.Close()
171+
defer func() {
172+
// Unbind does polite quit and closes the connection.
173+
// But when it fails, we need to ensure the connection is closed for sure.
174+
if err := ldapClient.Unbind(); err != nil {
175+
_ = ldapClient.Close()
176+
}
177+
}()
172178

173179
pruneBuilder, err := buildPruneBuilder(ldapClient, o.Config)
174180
if err != nil {

pkg/cli/admin/groups/sync/sync.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,13 @@ func (o *SyncOptions) Run() error {
366366
if err != nil {
367367
return err
368368
}
369-
defer ldapClient.Close()
369+
defer func() {
370+
// Unbind does polite quit and closes the connection.
371+
// But when it fails, we need to ensure the connection is closed for sure.
372+
if err := ldapClient.Unbind(); err != nil {
373+
_ = ldapClient.Close()
374+
}
375+
}()
370376

371377
errorHandler := o.CreateErrorHandler()
372378

0 commit comments

Comments
 (0)