Skip to content

Commit 448017c

Browse files
committed
modify timeout settings
1 parent 8b93cf3 commit 448017c

File tree

28 files changed

+122
-147
lines changed

28 files changed

+122
-147
lines changed

cmd/protoc-gen-go-rpc-tmpl/internal/generate/service/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ import (
263263
func Test_service_{{.LowerName}}_methods(t *testing.T) {
264264
conn := getRPCClientConnForTest()
265265
cli := serverNameExampleV1.New{{.Name}}Client(conn)
266-
ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
266+
ctx := context.Background()
267267
268268
tests := []struct {
269269
name string

cmd/serverNameExample_grpcExample/initial/createService.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package initial
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/zhufuyi/sponge/pkg/app"
98
"github.com/zhufuyi/sponge/pkg/logger"
@@ -25,8 +24,6 @@ func CreateServices() []app.IServer {
2524
grpcAddr := ":" + strconv.Itoa(cfg.Grpc.Port)
2625
grpcRegistry, grpcInstance := registerService("grpc", cfg.App.Host, cfg.Grpc.Port)
2726
grpcServer := server.NewGRPCServer(grpcAddr,
28-
server.WithGrpcReadTimeout(time.Duration(cfg.Grpc.ReadTimeout)*time.Second),
29-
server.WithGrpcWriteTimeout(time.Duration(cfg.Grpc.WriteTimeout)*time.Second),
3027
server.WithGrpcRegistry(grpcRegistry, grpcInstance),
3128
)
3229
servers = append(servers, grpcServer)

cmd/serverNameExample_grpcGwPbExample/initial/createService.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package initial
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/zhufuyi/sponge/pkg/app"
98
"github.com/zhufuyi/sponge/pkg/logger"
@@ -25,8 +24,6 @@ func CreateServices() []app.IServer {
2524
httpAddr := ":" + strconv.Itoa(cfg.HTTP.Port)
2625
httpRegistry, httpInstance := registerService("http", cfg.App.Host, cfg.HTTP.Port)
2726
httpServer := server.NewHTTPServer_pbExample(httpAddr,
28-
server.WithHTTPReadTimeout(time.Second*time.Duration(cfg.HTTP.ReadTimeout)),
29-
server.WithHTTPWriteTimeout(time.Second*time.Duration(cfg.HTTP.WriteTimeout)),
3027
server.WithHTTPRegistry(httpRegistry, httpInstance),
3128
server.WithHTTPIsProd(cfg.App.Env == "prod"),
3229
)

cmd/serverNameExample_grpcHttpPbExample/initial/createService.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package initial
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/zhufuyi/sponge/pkg/app"
98
"github.com/zhufuyi/sponge/pkg/logger"
@@ -25,8 +24,6 @@ func CreateServices() []app.IServer {
2524
httpAddr := ":" + strconv.Itoa(cfg.HTTP.Port)
2625
httpRegistry, httpInstance := registerService("http", cfg.App.Host, cfg.HTTP.Port)
2726
httpServer := server.NewHTTPServer(httpAddr,
28-
server.WithHTTPReadTimeout(time.Second*time.Duration(cfg.HTTP.ReadTimeout)),
29-
server.WithHTTPWriteTimeout(time.Second*time.Duration(cfg.HTTP.WriteTimeout)),
3027
server.WithHTTPRegistry(httpRegistry, httpInstance),
3128
server.WithHTTPIsProd(cfg.App.Env == "prod"),
3229
)
@@ -36,8 +33,6 @@ func CreateServices() []app.IServer {
3633
grpcAddr := ":" + strconv.Itoa(cfg.Grpc.Port)
3734
grpcRegistry, grpcInstance := registerService("grpc", cfg.App.Host, cfg.Grpc.Port)
3835
grpcServer := server.NewGRPCServer(grpcAddr,
39-
server.WithGrpcReadTimeout(time.Duration(cfg.Grpc.ReadTimeout)*time.Second),
40-
server.WithGrpcWriteTimeout(time.Duration(cfg.Grpc.WriteTimeout)*time.Second),
4136
server.WithGrpcRegistry(grpcRegistry, grpcInstance),
4237
)
4338
servers = append(servers, grpcServer)

cmd/serverNameExample_grpcPbExample/initial/createService.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package initial
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/zhufuyi/sponge/pkg/app"
98
"github.com/zhufuyi/sponge/pkg/logger"
@@ -25,8 +24,6 @@ func CreateServices() []app.IServer {
2524
grpcAddr := ":" + strconv.Itoa(cfg.Grpc.Port)
2625
grpcRegistry, grpcInstance := registerService("grpc", cfg.App.Host, cfg.Grpc.Port)
2726
grpcServer := server.NewGRPCServer(grpcAddr,
28-
server.WithGrpcReadTimeout(time.Duration(cfg.Grpc.ReadTimeout)*time.Second),
29-
server.WithGrpcWriteTimeout(time.Duration(cfg.Grpc.WriteTimeout)*time.Second),
3027
server.WithGrpcRegistry(grpcRegistry, grpcInstance),
3128
)
3229
servers = append(servers, grpcServer)

cmd/serverNameExample_httpExample/initial/createService.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package initial
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/zhufuyi/sponge/pkg/app"
98
"github.com/zhufuyi/sponge/pkg/logger"
@@ -25,8 +24,6 @@ func CreateServices() []app.IServer {
2524
httpAddr := ":" + strconv.Itoa(cfg.HTTP.Port)
2625
httpRegistry, httpInstance := registerService("http", cfg.App.Host, cfg.HTTP.Port)
2726
httpServer := server.NewHTTPServer(httpAddr,
28-
server.WithHTTPReadTimeout(time.Second*time.Duration(cfg.HTTP.ReadTimeout)),
29-
server.WithHTTPWriteTimeout(time.Second*time.Duration(cfg.HTTP.WriteTimeout)),
3027
server.WithHTTPRegistry(httpRegistry, httpInstance),
3128
server.WithHTTPIsProd(cfg.App.Env == "prod"),
3229
)

cmd/serverNameExample_httpPbExample/initial/createService.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package initial
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/zhufuyi/sponge/pkg/app"
98
"github.com/zhufuyi/sponge/pkg/logger"
@@ -25,8 +24,6 @@ func CreateServices() []app.IServer {
2524
httpAddr := ":" + strconv.Itoa(cfg.HTTP.Port)
2625
httpRegistry, httpInstance := registerService("http", cfg.App.Host, cfg.HTTP.Port)
2726
httpServer := server.NewHTTPServer_pbExample(httpAddr,
28-
server.WithHTTPReadTimeout(time.Second*time.Duration(cfg.HTTP.ReadTimeout)),
29-
server.WithHTTPWriteTimeout(time.Second*time.Duration(cfg.HTTP.WriteTimeout)),
3027
server.WithHTTPRegistry(httpRegistry, httpInstance),
3128
server.WithHTTPIsProd(cfg.App.Env == "prod"),
3229
)

cmd/serverNameExample_mixExample/initial/createService.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package initial
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/zhufuyi/sponge/pkg/app"
98
"github.com/zhufuyi/sponge/pkg/logger"
@@ -25,8 +24,6 @@ func CreateServices() []app.IServer {
2524
httpAddr := ":" + strconv.Itoa(cfg.HTTP.Port)
2625
httpRegistry, httpInstance := registerService("http", cfg.App.Host, cfg.HTTP.Port)
2726
httpServer := server.NewHTTPServer(httpAddr,
28-
server.WithHTTPReadTimeout(time.Second*time.Duration(cfg.HTTP.ReadTimeout)),
29-
server.WithHTTPWriteTimeout(time.Second*time.Duration(cfg.HTTP.WriteTimeout)),
3027
server.WithHTTPRegistry(httpRegistry, httpInstance),
3128
server.WithHTTPIsProd(cfg.App.Env == "prod"),
3229
)
@@ -36,8 +33,6 @@ func CreateServices() []app.IServer {
3633
grpcAddr := ":" + strconv.Itoa(cfg.Grpc.Port)
3734
grpcRegistry, grpcInstance := registerService("grpc", cfg.App.Host, cfg.Grpc.Port)
3835
grpcServer := server.NewGRPCServer(grpcAddr,
39-
server.WithGrpcReadTimeout(time.Duration(cfg.Grpc.ReadTimeout)*time.Second),
40-
server.WithGrpcWriteTimeout(time.Duration(cfg.Grpc.WriteTimeout)*time.Second),
4136
server.WithGrpcRegistry(grpcRegistry, grpcInstance),
4237
)
4338
servers = append(servers, grpcServer)

cmd/sponge/commands/generate/template.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func NewCenter(configFile string) (*Center, error) {
392392
httpServerConfigCode = `# http server settings
393393
http:
394394
port: 8080 # listen port
395-
timeout: 10 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s`
395+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s`
396396

397397
rpcServerConfigCode = `# grpc server settings
398398
grpc:
@@ -415,6 +415,7 @@ grpcClient:
415415
- name: "your_grpc_service_name" # grpc service name, used for service discovery
416416
host: "127.0.0.1" # grpc service address, used for direct connection
417417
port: 8282 # grpc service port
418+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, valid only for unary grpc type
418419
registryDiscoveryType: "" # registration and discovery types: consul, etcd, nacos, if empty, connecting to server using host and port
419420
enableLoadBalance: true # whether to turn on the load balancer
420421
# clientSecure parameter setting
@@ -435,14 +436,15 @@ grpcClient:
435436
rpcGwServerConfigCode = `# http server settings
436437
http:
437438
port: 8080 # listen port
438-
timeout: 10 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s
439+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s
439440
440441
441442
# grpc client-side settings, support for setting up multiple grpc clients.
442443
grpcClient:
443444
- name: "your_grpc_service_name" # grpc service name, used for service discovery
444445
host: "127.0.0.1" # grpc service address, used for direct connection
445446
port: 8282 # grpc service port
447+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, valid only for unary grpc type
446448
registryDiscoveryType: "" # registration and discovery types: consul, etcd, nacos, if empty, connecting to server using host and port
447449
enableLoadBalance: true # whether to turn on the load balancer
448450
# clientSecure parameter setting
@@ -463,7 +465,7 @@ grpcClient:
463465
grpcAndHTTPServerConfigCode = `# http server settings
464466
http:
465467
port: 8080 # listen port
466-
timeout: 10 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s
468+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s
467469
468470
469471
# grpc server settings
@@ -487,6 +489,7 @@ grpcClient:
487489
- name: "your_grpc_service_name" # grpc service name, used for service discovery
488490
host: "127.0.0.1" # grpc service address, used for direct connection
489491
port: 8282 # grpc service port
492+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, valid only for unary grpc type
490493
registryDiscoveryType: "" # registration and discovery types: consul, etcd, nacos, if empty, connecting to server using host and port
491494
enableLoadBalance: true # whether to turn on the load balancer
492495
# clientSecure parameter setting

configs/serverNameExample.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ app:
2222
# http server settings
2323
http:
2424
port: 8080 # listen port
25-
readTimeout: 5 # read timeout, unit(second)
26-
writeTimeout: 5 # write timeout, unit(second), if enableHTTPProfile is true, it needs to be greater than 60s, the default value for pprof to do profiling is 60s
25+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, if enableHTTPProfile is true, it needs to set 0 or greater than 60s
2726

2827

2928
# grpc server settings
3029
grpc:
3130
port: 8282 # listen port
3231
httpPort: 8283 # profile and metrics ports
33-
readTimeout: 5 # read timeout, unit(second)
34-
writeTimeout: 5 # write timeout, unit(second)
3532
enableToken: false # whether to enable server-side token authentication, default appID=grpc, appKey=123456
3633
# serverSecure parameter setting
3734
# if type="", it means no secure connection, no need to fill in any parameters
@@ -49,6 +46,7 @@ grpcClient:
4946
- name: "serverNameExample" # grpc service name, used for service discovery
5047
host: "127.0.0.1" # grpc service address, used for direct connection
5148
port: 8282 # grpc service port
49+
timeout: 0 # request timeout, unit(second), if 0 means not set, if greater than 0 means set timeout, valid only for unary grpc type
5250
registryDiscoveryType: "" # registration and discovery types: consul, etcd, nacos, if empty, connecting to server using host and port
5351
enableLoadBalance: true # whether to turn on the load balancer
5452
# clientSecure parameter setting

0 commit comments

Comments
 (0)