don't schedule sending when stream.Write is called after the deadline

This commit is contained in:
Marten Seemann
2017-12-18 22:11:47 +07:00
parent 3245c81bbc
commit d4b80bd8d0
2 changed files with 4 additions and 0 deletions

View File

@@ -81,6 +81,9 @@ func (s *sendStream) Write(p []byte) (int, error) {
if s.closeForShutdownErr != nil { if s.closeForShutdownErr != nil {
return 0, s.closeForShutdownErr return 0, s.closeForShutdownErr
} }
if !s.writeDeadline.IsZero() && !time.Now().Before(s.writeDeadline) {
return 0, errDeadline
}
if len(p) == 0 { if len(p) == 0 {
return 0, nil return 0, nil
} }

View File

@@ -208,6 +208,7 @@ var _ = Describe("Send Stream", func() {
n, err := strWithTimeout.Write([]byte("foobar")) n, err := strWithTimeout.Write([]byte("foobar"))
Expect(err).To(MatchError(errDeadline)) Expect(err).To(MatchError(errDeadline))
Expect(n).To(BeZero()) Expect(n).To(BeZero())
Expect(onDataCalled).To(BeFalse())
}) })
It("unblocks after the deadline", func() { It("unblocks after the deadline", func() {