Skip to content

Commit 4571897

Browse files
committed
Avoid creating closures for resetPingStrikes
1 parent 207b5d8 commit 4571897

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Diff for: internal/transport/http2_server.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ func (t *http2Server) WriteHeader(s *Stream, md metadata.MD) error {
766766
return nil
767767
}
768768

769+
func (t *http2Server) setResetPingStrikes() {
770+
atomic.StoreUint32(&t.resetPingStrikes, 1)
771+
}
772+
769773
func (t *http2Server) writeHeaderLocked(s *Stream) error {
770774
// TODO(mmukhi): Benchmark if the performance gets better if count the metadata and other header fields
771775
// first and create a slice of that exact size.
@@ -780,9 +784,7 @@ func (t *http2Server) writeHeaderLocked(s *Stream) error {
780784
streamID: s.id,
781785
hf: headerFields,
782786
endStream: false,
783-
onWrite: func() {
784-
atomic.StoreUint32(&t.resetPingStrikes, 1)
785-
},
787+
onWrite: t.setResetPingStrikes,
786788
})
787789
if !success {
788790
if err != nil {
@@ -842,9 +844,7 @@ func (t *http2Server) WriteStatus(s *Stream, st *status.Status) error {
842844
streamID: s.id,
843845
hf: headerFields,
844846
endStream: true,
845-
onWrite: func() {
846-
atomic.StoreUint32(&t.resetPingStrikes, 1)
847-
},
847+
onWrite: t.setResetPingStrikes,
848848
}
849849
s.hdrMu.Unlock()
850850
success, err := t.controlBuf.execute(t.checkForHeaderListSize, trailingHeader)
@@ -899,9 +899,7 @@ func (t *http2Server) Write(s *Stream, hdr []byte, data []byte, opts *Options) e
899899
streamID: s.id,
900900
h: hdr,
901901
d: data,
902-
onEachWrite: func() {
903-
atomic.StoreUint32(&t.resetPingStrikes, 1)
904-
},
902+
onEachWrite: t.setResetPingStrikes,
905903
}
906904
if err := s.wq.get(int32(len(hdr) + len(data))); err != nil {
907905
select {

0 commit comments

Comments
 (0)