-
Notifications
You must be signed in to change notification settings - Fork 21
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
How to handle "sonic connection is closed" error at runtime? #14
Comments
Hello, thanks you for your issue ! Can you provide an example of the problem please. Have a nice day. |
@alexisvisco it occurs at random time, it just got error like package sosonic
import (
"sync"
"time"
"github.com/expectedsh/go-sonic/sonic"
log "github.com/sirupsen/logrus"
)
// SoSonic :nodoc:
type SoSonic struct {
host string
port int
secret string
Ingester sonic.Ingestable
Searcher sonic.Searchable
}
// New :nodoc:
func New(host string, port int, secret string) *SoSonic {
ingester, err := sonic.NewIngester(host, port, secret)
if err != nil {
log.Error(err)
}
searcher, err := sonic.NewSearch(host, port, secret)
if err != nil {
log.Error(err)
}
ss := &SoSonic{
Ingester: ingester,
Searcher: searcher,
host: host,
port: port,
secret: secret,
}
go ss.check()
return ss
}
func (s *SoSonic) check() {
for {
mu := sync.Mutex{}
mu.Lock()
s.trySearcher()
s.tryIngester()
mu.Unlock()
time.Sleep(10 * time.Second)
}
}
func (s *SoSonic) tryIngester() {
err := s.Ingester.Ping()
if err != nil {
log.Info("try reconnect ingester")
ingester, err := sonic.NewIngester(s.host, s.port, s.secret)
if err != nil {
log.Error(err)
} else {
s.Ingester = ingester
log.Info("ingester reconnected")
}
return
}
}
func (s *SoSonic) trySearcher() {
err := s.Searcher.Ping()
if err != nil {
log.Info("try reconnect searcher")
searcher, err := sonic.NewSearch(s.host, s.port, s.secret)
if err != nil {
log.Error(err)
} else {
s.Searcher = searcher
log.Info("searcher reconnected")
}
return
}
} With this wrapper it will |
In case if anyone stumbles upon this same problem, it might be because of the There are few ways that I can think of to solve this
|
Thanks @tanqhnguyen for the reply, I am quite busy at the moment but when I will be available again I will implement the #11 with the ping connection in the connection pool in mind. |
@alexisvisco that's ok :) I happen to need this at the moment so I might as well try to implement the connection pool for it. I will try to put together a POC and we can discuss further. Of course if you happen to have anything WIP, we can continue from there |
I think, this issue can be closed then. Would like to see the connection poll implementation. |
When the app is running, how to properly handle "sonic connection is closed" error ? Can it implement
retry to connect
?The text was updated successfully, but these errors were encountered: