1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-09 09:35:03 +09:00

yamux keep-alive config + remove write deadline for sub conns

This commit is contained in:
Sergey Cherepanov 2023-06-13 13:28:19 +02:00
parent 767f868a36
commit 05b479e5fa
No known key found for this signature in database
GPG key ID: 87F8EDE8FBDF637C
3 changed files with 13 additions and 6 deletions

View file

@ -5,7 +5,8 @@ type configGetter interface {
}
type Config struct {
ListenAddrs []string `yaml:"listenAddrs"`
WriteTimeoutSec int `yaml:"writeTimeoutSec"`
DialTimeoutSec int `yaml:"dialTimeoutSec"`
ListenAddrs []string `yaml:"listenAddrs"`
WriteTimeoutSec int `yaml:"writeTimeoutSec"`
DialTimeoutSec int `yaml:"dialTimeoutSec"`
KeepAlivePeriodSec int `yaml:"keepAlivePeriodSec"`
}

View file

@ -29,7 +29,6 @@ func (y *yamuxConn) Open(ctx context.Context) (conn net.Conn, err error) {
if conn, err = y.Session.Open(); err != nil {
return
}
conn = connutil.NewTimeout(conn, time.Second*10)
return
}
@ -52,6 +51,5 @@ func (y *yamuxConn) Accept() (conn net.Conn, err error) {
}
return
}
conn = connutil.NewTimeout(conn, time.Second*10)
return
}

View file

@ -51,8 +51,16 @@ func (y *yamuxTransport) Init(a *app.App) (err error) {
if y.conf.WriteTimeoutSec <= 0 {
y.conf.WriteTimeoutSec = 10
}
y.yamuxConf = yamux.DefaultConfig()
y.yamuxConf.EnableKeepAlive = false
if y.conf.KeepAlivePeriodSec < 0 {
y.yamuxConf.EnableKeepAlive = false
} else {
y.yamuxConf.EnableKeepAlive = true
if y.conf.KeepAlivePeriodSec != 0 {
y.yamuxConf.KeepAliveInterval = time.Duration(y.conf.KeepAlivePeriodSec) * time.Second
}
}
y.yamuxConf.StreamOpenTimeout = time.Duration(y.conf.DialTimeoutSec) * time.Second
y.yamuxConf.ConnectionWriteTimeout = time.Duration(y.conf.WriteTimeoutSec) * time.Second
y.listCtx, y.listCtxCancel = context.WithCancel(context.Background())