fix nil pointer dereference in repositories
increase default websocket ConnectionReadLimit to 4 MB, add to configuration
This commit is contained in:
1 parent
4553cd0261
commit
7a06660597
7 files changed
+47
-16
No files matched your search
Generated
+3
-3
@@ -277,7 +277,7 @@
|
||||
version = "v2.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8c3ec5a8ef8f4db927ab30671f00486a2d0ef4e03345f261cf9369a2ae27877a"
|
||||
digest = "1:d30832edf4ae7a45e863e216c89bb5f1d66c10ff5b3255b9e007598a048594d7"
|
||||
name = "github.com/integration-system/isp-lib"
|
||||
packages = [
|
||||
"atomic",
|
||||
@@ -293,8 +293,8 @@
|
||||
"utils",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "9ecfa413468d829dce66fe95562b4366b0dfb2a0"
|
||||
version = "v2.0.0"
|
||||
revision = "abfa9a9776d64e6d04d495bfe00db8ca4dcbe7fc"
|
||||
version = "v2.0.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:1562269205ab0c6685c8b0b99511e91b9d3627e4cac3f0288378bc8930e658f1"
|
||||
|
||||
@@ -9,8 +9,9 @@ type Configuration struct {
|
||||
GrpcOuterAddress structure.AddressConfiguration `valid:"required~Required" json:"grpcOuterAddress"`
|
||||
ModuleName string `valid:"required~Required"`
|
||||
WS struct {
|
||||
Rest structure.AddressConfiguration `valid:"required~Required"`
|
||||
Grpc structure.AddressConfiguration `valid:"required~Required"`
|
||||
Rest structure.AddressConfiguration `valid:"required~Required"`
|
||||
Grpc structure.AddressConfiguration `valid:"required~Required"`
|
||||
WsConnectionReadLimitKB int64 `schema:"Максимальное количество килобайт на чтение по вебсокету,при превышении соединение закрывается с ошибкой"`
|
||||
}
|
||||
Metrics structure.MetricConfiguration
|
||||
Cluster ClusterConfiguration `valid:"required~Required"`
|
||||
|
||||
@@ -30,7 +30,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
moduleName = "config"
|
||||
moduleName = "config"
|
||||
defaultWsConnectionReadLimit int64 = 4 << 20 // 4 MB
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -85,7 +86,7 @@ func main() {
|
||||
}
|
||||
|
||||
_, raftStore := initRaft(raftListener, cfg.Cluster, declaration)
|
||||
initWebsocket(ctx, httpListener, raftStore)
|
||||
initWebsocket(ctx, cfg.WS.WsConnectionReadLimitKB, httpListener, raftStore)
|
||||
initGrpc(cfg.WS.Grpc, raftStore)
|
||||
|
||||
defer goodbye.Exit(ctx, -1)
|
||||
@@ -117,9 +118,14 @@ func initMultiplexer(addressConfiguration structure.AddressConfiguration) (net.L
|
||||
return httpListener, raftListener, nil
|
||||
}
|
||||
|
||||
func initWebsocket(ctx context.Context, listener net.Listener, raftStore *store.Store) {
|
||||
func initWebsocket(ctx context.Context, wsConnectionReadLimitKB int64, listener net.Listener, raftStore *store.Store) {
|
||||
connectionReadLimit := defaultWsConnectionReadLimit
|
||||
if wsConnectionReadLimitKB > 0 {
|
||||
connectionReadLimit = wsConnectionReadLimitKB << 10
|
||||
}
|
||||
etpConfig := etp.ServerConfig{
|
||||
InsecureSkipVerify: true,
|
||||
InsecureSkipVerify: true,
|
||||
ConnectionReadLimit: connectionReadLimit,
|
||||
}
|
||||
etpServer := etp.NewServer(ctx, etpConfig)
|
||||
subs.NewSocketEventHandler(etpServer, raftStore).SubscribeAll()
|
||||
|
||||
@@ -32,6 +32,9 @@ func (r *commonConfigRepPg) Upsert(config entity.CommonConfig) (*entity.CommonCo
|
||||
Insert()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &config, err
|
||||
}
|
||||
|
||||
@@ -44,5 +47,8 @@ func (r *commonConfigRepPg) Delete(identities []string) (int, error) {
|
||||
Delete()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected(), err
|
||||
}
|
||||
@@ -32,6 +32,9 @@ func (r *configRepPg) Upsert(config entity.Config) (*entity.Config, error) {
|
||||
Insert()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &config, err
|
||||
}
|
||||
|
||||
@@ -44,5 +47,8 @@ func (r *configRepPg) Delete(identities []string) (int, error) {
|
||||
Delete()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected(), err
|
||||
}
|
||||
+9
-3
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
type ModulesRepository interface {
|
||||
Snapshot() ([]entity.Module, error)
|
||||
Upsert(module entity.Module) (entity.Module, error)
|
||||
Upsert(module entity.Module) (*entity.Module, error)
|
||||
Delete(identities []string) (int, error)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func (r *modulesRepPg) Snapshot() ([]entity.Module, error) {
|
||||
return modules, err
|
||||
}
|
||||
|
||||
func (r *modulesRepPg) Upsert(module entity.Module) (entity.Module, error) {
|
||||
func (r *modulesRepPg) Upsert(module entity.Module) (*entity.Module, error) {
|
||||
err := r.rxClient.Visit(func(db *pg.DB) error {
|
||||
_, err := db.Model(&module).
|
||||
OnConflict("(id) DO UPDATE").
|
||||
@@ -32,7 +32,10 @@ func (r *modulesRepPg) Upsert(module entity.Module) (entity.Module, error) {
|
||||
Insert()
|
||||
return err
|
||||
})
|
||||
return module, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &module, err
|
||||
}
|
||||
|
||||
func (r *modulesRepPg) Delete(identities []string) (int, error) {
|
||||
@@ -43,5 +46,8 @@ func (r *modulesRepPg) Delete(identities []string) (int, error) {
|
||||
Where("id IN (?)", pg.In(identities)).Delete()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected(), err
|
||||
}
|
||||
+10
-4
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
type SchemaRepository interface {
|
||||
Snapshot() ([]entity.ConfigSchema, error)
|
||||
Upsert(s entity.ConfigSchema) (*entity.ConfigSchema, error)
|
||||
Upsert(schema entity.ConfigSchema) (*entity.ConfigSchema, error)
|
||||
Delete(identities []string) (int, error)
|
||||
}
|
||||
|
||||
@@ -24,15 +24,18 @@ func (r *schemaRepPg) Snapshot() ([]entity.ConfigSchema, error) {
|
||||
return schemas, err
|
||||
}
|
||||
|
||||
func (r *schemaRepPg) Upsert(s entity.ConfigSchema) (*entity.ConfigSchema, error) {
|
||||
func (r *schemaRepPg) Upsert(schema entity.ConfigSchema) (*entity.ConfigSchema, error) {
|
||||
err := r.rxClient.Visit(func(db *pg.DB) error {
|
||||
_, err := db.Model(&s).
|
||||
_, err := db.Model(&schema).
|
||||
OnConflict("(id) DO UPDATE").
|
||||
Returning("*").
|
||||
Insert()
|
||||
return err
|
||||
})
|
||||
return &s, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &schema, err
|
||||
}
|
||||
|
||||
func (r *schemaRepPg) Delete(identities []string) (int, error) {
|
||||
@@ -43,5 +46,8 @@ func (r *schemaRepPg) Delete(identities []string) (int, error) {
|
||||
Where("id IN (?)", pg.In(identities)).Delete()
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected(), err
|
||||
}
|
||||
Reference in new issue
Block a user