-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: batch channel not close when client close #123
Conversation
a2222d4
to
4a98395
Compare
the client will block because the channel is not closed, a simple demo to verify the idea, package main
import (
"fmt"
"time"
)
func reader(ch <-chan int) {
for record := range ch {
fmt.Println(record)
}
fmt.Println("End of data")
}
func main() {
var ch = make(chan int)
go reader(ch)
for i := 0; i < 10; i++ {
ch <- i
}
time.Sleep(time.Second * 10)
} |
Currently, we don't have any restrictions, so we can still call |
|
Close method: func (c *client) Close() error {
c.batchContextCancel()
c.dataChanMap.Range(func(key, value interface{}) bool {
close(value.(chan *sendBatchWithCB))
c.dataChanMap.Delete(key)
return true
})
return nil
} WritePointWithRp method on new line 58, add a context cancel judgment to prevent the program from writing data to a closed channel: if c.batchContext.Err() != nil {
return errors.New("batch write failed, error: " + c.batchContext.Err().Error())
} |
b27dcfa
to
cc17f8e
Compare
Signed-off-by: cyruslo <[email protected]> Signed-off-by: ZhangJian He <[email protected]> Co-authored-by: ZhangJian He <[email protected]> Signed-off-by: ZhangJian He <[email protected]>
Fix #100