Skip to content

Commit fdb9474

Browse files
elza2yuanyouprestonvasquez
authored
fix: fixed a memory leak caused by the commandMonitor example closure. (#1180)
Co-authored-by: Preston Vasquez <[email protected]> Co-authored-by: Preston Vasquez <[email protected]> --------- Co-authored-by: yuanyou <[email protected]> Co-authored-by: Preston Vasquez <[email protected]>
1 parent 0d0b23b commit fdb9474

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

event/examples_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ func ExampleCommandMonitor() {
3232
startedCommands[evt.RequestID],
3333
evt.Reply,
3434
)
35+
36+
// Empty "startedCommands" for the request ID to avoid a memory leak.
37+
delete(startedCommands, evt.RequestID)
3538
},
3639
Failed: func(_ context.Context, evt *event.CommandFailedEvent) {
3740
log.Printf("Command: %v Failure: %v\n",
3841
startedCommands[evt.RequestID],
3942
evt.Failure,
4043
)
44+
45+
// Empty "startedCommands" for the request ID to avoid a memory leak.
46+
delete(startedCommands, evt.RequestID)
4147
},
4248
}
4349
clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetMonitor(cmdMonitor)

0 commit comments

Comments
 (0)