Skip to content

Commit 60497f9

Browse files
committed
update
1 parent 4440597 commit 60497f9

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

codegen/tml/config/template_config.go

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ type CrpcClientConfig struct {
270270
271271
//WebServerConfig -
272272
type WebServerConfig struct {
273+
CloseMode int $json:"close_mode"$
273274
ConnectTimeout ctime.Duration $json:"connect_timeout"$ //default 500ms,max time to finish the handshake and read each whole request
274275
GlobalTimeout ctime.Duration $json:"global_timeout"$ //default 500ms,max time to handle the request,unless the specific handle timeout is used in HandlerTimeout in AppConfig,handler's timeout will also be effected by caller's deadline
275276
IdleTimeout ctime.Duration $json:"idle_timeout"$ //default 5s

codegen/tml/configfile/template_configfile.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const textsource = `{
2828
"heart_probe":"1.5s"
2929
},
3030
"web_server":{
31+
"close_mode":0,
3132
"connect_timeout":"200ms",
3233
"global_timeout":"200ms",
3334
"idle_timeout":"5s",

codegen/tml/gomod/template_gomod.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ go 1.18
1212
1313
require (
1414
github.com/chenjie199234/config v0.0.1
15-
github.com/chenjie199234/Corelib v0.0.61
15+
github.com/chenjie199234/Corelib v0.0.62
1616
github.com/fsnotify/fsnotify v1.5.1
1717
github.com/go-sql-driver/mysql v1.6.0
1818
github.com/segmentio/kafka-go v0.4.31
19-
go.mongodb.org/mongo-driver v1.8.4
19+
go.mongodb.org/mongo-driver v1.9.0
2020
google.golang.org/protobuf v1.28.0
2121
)`
2222

codegen/tml/server/xweb/template_xweb.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var s *web.WebServer
2929
func StartWebServer() {
3030
c := config.GetWebServerConfig()
3131
webc := &web.ServerConfig{
32+
CloseMode: c.CloseMode,
3233
ConnectTimeout: time.Duration(c.ConnectTimeout),
3334
GlobalTimeout: time.Duration(c.GlobalTimeout),
3435
IdleTimeout: time.Duration(c.IdleTimeout),

web/server.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ import (
3232
type OutsideHandler func(*Context)
3333

3434
type ServerConfig struct {
35-
//when server close,server will wait at least this time before close,every request will refresh the time
35+
//when server close,server will wait at least this time before close
3636
//min is 1 second
37-
WaitCloseTime time.Duration
37+
WaitCloseTime time.Duration
38+
//mode 0:must have no active requests and must wait at lease WaitCloseTime
39+
// every new request come in when the server is closing will refresh the WaitCloseTime
40+
//mode 1:must have no active requests and must wait at lease WaitCloseTime
41+
// WaitCloseTime will not be refreshed by new requests
42+
WaitCloseMode int
3843
ConnectTimeout time.Duration //max time for read the whole request,including the tls handshake
3944
GlobalTimeout time.Duration //request's max handling time
4045
//if this is negative,it is same as disable keep alive,each request will take a new tcp connection,when request finish,tcp closed
@@ -454,8 +459,10 @@ func (s *WebServer) insideHandler(method, path string, handlers []OutsideHandler
454459
break
455460
}
456461
} else {
457-
//refresh close wait
458-
s.closewaittimer.Reset(s.c.WaitCloseTime)
462+
if s.c.WaitCloseMode == 0 {
463+
//refresh close wait
464+
s.closewaittimer.Reset(s.c.WaitCloseTime)
465+
}
459466
//tell peer self closed
460467
w.Header().Set("Content-Type", "application/json")
461468
w.WriteHeader(int(cerror.ErrClosing.Httpcode))

0 commit comments

Comments
 (0)