Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update streaming handler #196

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ require (
github.com/roadrunner-server/endure/v2 v2.4.3
github.com/roadrunner-server/errors v1.3.0
github.com/roadrunner-server/goridge/v3 v3.8.1
github.com/roadrunner-server/sdk/v4 v4.5.5
github.com/roadrunner-server/sdk/v4 v4.5.6
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1
go.opentelemetry.io/contrib/propagators/jaeger v1.21.1
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/trace v1.21.0
go.uber.org/zap v1.26.0
golang.org/x/net v0.19.0
golang.org/x/net v0.20.0
golang.org/x/sys v0.16.0
)

Expand Down Expand Up @@ -60,7 +60,7 @@ require (
go.uber.org/goleak v1.3.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.6.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ github.com/roadrunner-server/errors v1.3.0 h1:kLVXpXne0jMReN7pj8KIhyYyjqKjsPC5DR
github.com/roadrunner-server/errors v1.3.0/go.mod h1:XYVuhXvxi3yQaP/zCLB6QRZ0JvQIRaBa0SKFHL4WLKg=
github.com/roadrunner-server/goridge/v3 v3.8.1 h1:mdS5lDKQwPuVJ2jwW7l5cngJNJiie7xEGwpgw7a6CuQ=
github.com/roadrunner-server/goridge/v3 v3.8.1/go.mod h1:L5UkNzD8aKLz6TzpqmmiHOJ6EnsadsWEYNoqK/4qoK0=
github.com/roadrunner-server/sdk/v4 v4.5.5 h1:YNPV9yCG1tHQRN4vXs9V1xY9e+CQSbwNncrcFy7FWsA=
github.com/roadrunner-server/sdk/v4 v4.5.5/go.mod h1:M21tpBfCk3NEH2ixa/Fs80d7KGPVP9zwLrZhc/goi1Y=
github.com/roadrunner-server/sdk/v4 v4.5.6 h1:vfEYV0bHf/6Wi4qwLlNiwj5O239xpPKIc7Ho2kIcb3Q=
github.com/roadrunner-server/sdk/v4 v4.5.6/go.mod h1:M21tpBfCk3NEH2ixa/Fs80d7KGPVP9zwLrZhc/goi1Y=
github.com/roadrunner-server/tcplisten v1.4.0 h1:yWo09zktv/CSV6VywLfw4pwNcUchgTiIrW4uIICtO5M=
github.com/roadrunner-server/tcplisten v1.4.0/go.mod h1:A6+VSnW2ETGnN/e/CMdP63ZXqQDaC0UDMU6QmyuB0yM=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand Down Expand Up @@ -117,14 +117,14 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
36 changes: 36 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
err = h.Write(recv.Payload(), w)
if err != nil {
// send stop signal to the worker pool
stopCh <- struct{}{}
select {
case stopCh <- struct{}{}:
default:
}

req.Close(h.log, r)
h.putReq(req)
h.putCh(stopCh)
h.log.Error("write response error",
// we should not exit from the loop here, since after sending close signal, it should be closed from the SDK side
h.log.Error("write response (chunk) error",
zap.Time("start", start),
zap.Duration("elapsed", time.Since(start)),
zap.Error(err))
return
}
}

Expand Down Expand Up @@ -291,17 +291,15 @@ func (h *Handler) getPld() *payload.Payload {
}

func (h *Handler) getCh() chan struct{} {
ch := h.stopChPool.Get().(chan struct{})
return h.stopChPool.Get().(chan struct{})
}

func (h *Handler) putCh(ch chan struct{}) {
// just check if the chan is not empty
select {
case <-ch:
default:
}

return ch
}

func (h *Handler) putCh(ch chan struct{}) {
h.stopChPool.Put(ch)
}

Expand Down
3 changes: 1 addition & 2 deletions servers/fcgi/fcgi.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fcgi

import (
"context"
stderr "errors"
"log"
"net/http"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (s *Server) Server() any {
}

func (s *Server) Stop() {
err := s.fcgi.Shutdown(context.Background())
err := s.fcgi.Close()
if err != nil && !stderr.Is(err, http.ErrServerClosed) {
s.log.Error("fcgi shutdown", zap.Error(err))
}
Expand Down
13 changes: 8 additions & 5 deletions servers/http11/http.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package http

import (
"context"
stderr "errors"
"log"
"net/http"
Expand Down Expand Up @@ -47,9 +46,10 @@ func NewHTTPServer(handler http.Handler, cfg *config.Config, errLog *log.Logger,
MaxConcurrentStreams: cfg.HTTP2Config.MaxConcurrentStreams,
PermitProhibitedCipherSuites: false,
}),
ReadTimeout: time.Minute,
ReadHeaderTimeout: time.Minute,
WriteTimeout: time.Minute,
ReadTimeout: time.Minute * 5,
WriteTimeout: time.Minute * 5,
IdleTimeout: time.Hour,
ReadHeaderTimeout: time.Minute * 5,
ErrorLog: errLog,
},
}
Expand All @@ -60,6 +60,9 @@ func NewHTTPServer(handler http.Handler, cfg *config.Config, errLog *log.Logger,
redirectPort: redirectPort,
address: cfg.Address,
http: &http.Server{
ReadTimeout: time.Minute * 5,
WriteTimeout: time.Minute * 5,
IdleTimeout: time.Hour,
ReadHeaderTimeout: time.Minute * 5,
Handler: handler,
ErrorLog: errLog,
Expand Down Expand Up @@ -99,7 +102,7 @@ func (s *Server) Server() any {
}

func (s *Server) Stop() {
err := s.http.Shutdown(context.Background())
err := s.http.Close()
if err != nil && !stderr.Is(err, http.ErrServerClosed) {
s.log.Error("http shutdown", zap.Error(err))
}
Expand Down
3 changes: 1 addition & 2 deletions servers/https/https.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package https

import (
"context"
"crypto/tls"
"crypto/x509"
stderr "errors"
Expand Down Expand Up @@ -139,7 +138,7 @@ func (s *Server) Server() any {
}

func (s *Server) Stop() {
err := s.https.Shutdown(context.Background())
err := s.https.Close()
if err != nil && !stderr.Is(err, http.ErrServerClosed) {
s.log.Error("https shutdown", zap.Error(err))
}
Expand Down
12 changes: 6 additions & 6 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ require (
github.com/roadrunner-server/otel/v4 v4.3.10
github.com/roadrunner-server/resetter/v4 v4.0.19
github.com/roadrunner-server/rpc/v4 v4.2.13
github.com/roadrunner-server/sdk/v4 v4.5.5
github.com/roadrunner-server/sdk/v4 v4.5.6
github.com/roadrunner-server/send/v4 v4.2.13
github.com/roadrunner-server/server/v4 v4.5.5
github.com/roadrunner-server/static/v4 v4.1.13
github.com/stretchr/testify v1.8.4
github.com/yookoala/gofast v0.7.0
go.uber.org/zap v1.26.0
golang.org/x/net v0.19.0
golang.org/x/net v0.20.0
)

replace github.com/roadrunner-server/http/v4 => ../
Expand Down Expand Up @@ -125,17 +125,17 @@ require (
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
24 changes: 12 additions & 12 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ github.com/roadrunner-server/resetter/v4 v4.0.19 h1:TaUYM6/lir2FBJ/TvxDoaoNECX7G
github.com/roadrunner-server/resetter/v4 v4.0.19/go.mod h1:yF+Ys7c97wONQOVDHsZh5YfXoHeHUqrCnHquekm57fM=
github.com/roadrunner-server/rpc/v4 v4.2.13 h1:/x5fgnNE1Q2evBkTgtJFg4sFDokrMSFqHoBi+XLcUoc=
github.com/roadrunner-server/rpc/v4 v4.2.13/go.mod h1:Qwso+CQ0wWmMtWQpa5VczBiFSV+zaCmTLI9cuJ5I26M=
github.com/roadrunner-server/sdk/v4 v4.5.5 h1:YNPV9yCG1tHQRN4vXs9V1xY9e+CQSbwNncrcFy7FWsA=
github.com/roadrunner-server/sdk/v4 v4.5.5/go.mod h1:M21tpBfCk3NEH2ixa/Fs80d7KGPVP9zwLrZhc/goi1Y=
github.com/roadrunner-server/sdk/v4 v4.5.6 h1:vfEYV0bHf/6Wi4qwLlNiwj5O239xpPKIc7Ho2kIcb3Q=
github.com/roadrunner-server/sdk/v4 v4.5.6/go.mod h1:M21tpBfCk3NEH2ixa/Fs80d7KGPVP9zwLrZhc/goi1Y=
github.com/roadrunner-server/send/v4 v4.2.13 h1:Dnht7hpr4BxCOIYSsoTqF5SCbaGBWfswyuu7qKbVwVc=
github.com/roadrunner-server/send/v4 v4.2.13/go.mod h1:yKJQYdITGKXyBTdXZqZzv5jubLqRQQiUZWp7AxQe6YM=
github.com/roadrunner-server/server/v4 v4.5.5 h1:EUqqAjt3DWxrqP782FA4DgB4x9T+l/Cg29ssEAGI2Mg=
Expand Down Expand Up @@ -362,8 +362,8 @@ go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
Expand Down Expand Up @@ -392,8 +392,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -469,12 +469,12 @@ google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfG
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20210909211513-a8c4777a87af/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 h1:nz5NESFLZbJGPFxDT/HCn+V1mZ8JGNoY4nUpmW/Y2eg=
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917/go.mod h1:pZqR+glSb11aJ+JQcczCvgf47+duRuzNSKqE8YAQnV0=
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917 h1:rcS6EyEaoCO52hQDupoSfrxI3R6C2Tq741is7X8OvnM=
google.golang.org/genproto/googleapis/api v0.0.0-20240102182953-50ed04b92917/go.mod h1:CmlNWB9lSezaYELKS5Ym1r44VrrbPUa7JTvw+6MbpJ0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 h1:6G8oQ016D88m1xAKljMlBOOGWDZkes4kMhgGFlf8WcQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917/go.mod h1:xtjpI3tXFPP051KaWnhvxkiubL/6dJ18vLVf7q2pTOU=
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1 h1:/IWabOtPziuXTEtI1KYCpM6Ss7vaAkeMxk+uXV/xvZs=
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1/go.mod h1:+Rvu7ElI+aLzyDQhpHMFMMltsD6m7nqpuWDd2CwJw3k=
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1 h1:OPXtXn7fNMaXwO3JvOmF1QyTc00jsSFFz1vXXBOdCDo=
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1/go.mod h1:B5xPO//w8qmBDjGReYLpR6UJPnkldGkCSMoH/2vxJeg=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 h1:gphdwh0npgs8elJ4T6J+DQJHPVF7RsuJHCfwztUb4J4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA=
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
Expand Down
Loading