Skip to content

Commit b5819c9

Browse files
committed
update
1 parent b7c6014 commit b5819c9

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

cgrpc/balancer.go

+4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ func (b *corelibBalancer) Pick(info balancer.PickInfo) (balancer.PickResult, err
208208
for {
209209
server := b.c.c.Picker(b.getPickServers())
210210
if server != nil {
211+
if dl, ok := info.Ctx.Deadline(); ok && dl.UnixNano() <= time.Now().UnixNano()+int64(5*time.Millisecond) {
212+
//at least 5ms for net lag and server logic
213+
return balancer.PickResult{}, cerror.ErrDeadlineExceeded
214+
}
211215
atomic.AddInt32(&server.Pickinfo.Activecalls, 1)
212216
return balancer.PickResult{
213217
SubConn: server.subconn,

cgrpc/client.go

-5
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ func (c *CGrpcClient) Call(ctx context.Context, path string, req interface{}, re
189189
ctx, cancel = context.WithDeadline(ctx, time.Now().Add(c.c.GlobalTimeout))
190190
defer cancel()
191191
}
192-
dl, ok := ctx.Deadline()
193192
md := gmetadata.New(nil)
194193
if len(metadata) != 0 {
195194
d, _ := json.Marshal(metadata)
@@ -203,10 +202,6 @@ func (c *CGrpcClient) Call(ctx context.Context, path string, req interface{}, re
203202
ctx = gmetadata.NewOutgoingContext(ctx, md)
204203
for {
205204
start := time.Now()
206-
if ok && dl.UnixNano() <= start.UnixNano()+int64(5*time.Millisecond) {
207-
//at least 5ms for net lag and server logic
208-
return cerror.ErrDeadlineExceeded
209-
}
210205
p := &peer.Peer{}
211206
e := transGrpcError(c.conn.Invoke(ctx, path, req, resp, grpc.Peer(p)))
212207
end := time.Now()

codegen/tml/gomod/template_gomod.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const text = `module {{.}}
1111
go 1.17
1212
1313
require (
14-
github.com/chenjie199234/Config v0.0.26
15-
github.com/chenjie199234/Corelib v0.0.40
14+
github.com/chenjie199234/Config v0.0.27
15+
github.com/chenjie199234/Corelib v0.0.41
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.25
19-
go.mongodb.org/mongo-driver v1.8.1
19+
go.mongodb.org/mongo-driver v1.8.2
2020
google.golang.org/protobuf v1.27.1
2121
)`
2222

crpc/client.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ func (c *CrpcClient) Call(ctx context.Context, path string, in []byte, metadata
265265
r := c.getreq(msg)
266266
for {
267267
start := time.Now()
268-
if ok && dl.UnixNano() <= start.UnixNano()+int64(5*time.Millisecond) {
269-
//at least 5ms for net lag and server logic
270-
return nil, cerror.ErrDeadlineExceeded
271-
}
272268
server, e := c.balancer.Pick(ctx)
273269
if e != nil {
274270
return nil, e
275271
}
272+
if ok && dl.UnixNano() <= time.Now().UnixNano()+int64(5*time.Millisecond) {
273+
//at least 5ms for net lag and server logic
274+
return nil, cerror.ErrDeadlineExceeded
275+
}
276276
msg.Callid = atomic.AddUint64(&server.callid, 1)
277277
atomic.AddInt32(&server.Pickinfo.Activecalls, 1)
278278
if e = server.sendmessage(ctx, r); e != nil {

web/client.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"io"
1111
"net"
1212
"net/http"
13-
"net/textproto"
1413
"net/url"
1514
"os"
1615
"strconv"
@@ -132,16 +131,16 @@ func NewWebClient(c *ClientConfig, selfgroup, selfname, servergroup, servername
132131
}
133132

134133
func forbiddenHeader(header http.Header) bool {
135-
if _, ok := header[textproto.CanonicalMIMEHeaderKey("core_target")]; ok {
134+
if _, ok := header["Core_target"]; ok {
136135
return true
137136
}
138-
if _, ok := header[textproto.CanonicalMIMEHeaderKey("core_deadline")]; ok {
137+
if _, ok := header["Core_deadline"]; ok {
139138
return true
140139
}
141-
if _, ok := header[textproto.CanonicalMIMEHeaderKey("core_metadata")]; ok {
140+
if _, ok := header["Core_metadata"]; ok {
142141
return true
143142
}
144-
if _, ok := header[textproto.CanonicalMIMEHeaderKey("core_tracedata")]; ok {
143+
if _, ok := header["Core_tracedata"]; ok {
145144
return true
146145
}
147146
return false
@@ -247,8 +246,7 @@ func (this *WebClient) call(method string, ctx context.Context, path, query stri
247246
}
248247
req.Header = header
249248
//start call
250-
var resp *http.Response
251-
resp, e = this.httpclient.Do(req)
249+
resp, e := this.httpclient.Do(req)
252250
end := time.Now()
253251
if e != nil {
254252
e = cerror.ConvertStdError(e)

0 commit comments

Comments
 (0)