Skip to content

Commit

Permalink
fix: fixed a memory leak caused by the commandMonitor example closure. (
Browse files Browse the repository at this point in the history
mongodb#1180)

Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>

---------

Co-authored-by: yuanyou <yuanyou@kezaihui.com>
Co-authored-by: Preston Vasquez <prestonvasquez@icloud.com>
  • Loading branch information
3 people authored Feb 24, 2023
1 parent 0d0b23b commit fdb9474
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions event/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ func ExampleCommandMonitor() {
startedCommands[evt.RequestID],
evt.Reply,
)

// Empty "startedCommands" for the request ID to avoid a memory leak.
delete(startedCommands, evt.RequestID)
},
Failed: func(_ context.Context, evt *event.CommandFailedEvent) {
log.Printf("Command: %v Failure: %v\n",
startedCommands[evt.RequestID],
evt.Failure,
)

// Empty "startedCommands" for the request ID to avoid a memory leak.
delete(startedCommands, evt.RequestID)
},
}
clientOpts := options.Client().ApplyURI("mongodb://localhost:27017").SetMonitor(cmdMonitor)
Expand Down

0 comments on commit fdb9474

Please sign in to comment.