summaryrefslogtreecommitdiff
path: root/plugins/http
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-05-30 19:35:28 +0300
committerValery Piashchynski <[email protected]>2021-05-30 19:36:18 +0300
commit0ee91dc24d3e68706d89092c06b1c0d09dab0353 (patch)
treeb4699fc334ba7b13be475d54021d980960cff991 /plugins/http
parent8188b34646e29861071ab5270160a9665eb1832f (diff)
- Do not use response.writer in hijacked connection
- Remove atomics from the ws Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/http')
-rw-r--r--plugins/http/plugin.go32
1 files changed, 17 insertions, 15 deletions
diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go
index 397de7ae..c4a1a83f 100644
--- a/plugins/http/plugin.go
+++ b/plugins/http/plugin.go
@@ -6,8 +6,8 @@ import (
"log"
"net/http"
"sync"
+ "time"
- "github.com/hashicorp/go-multierror"
endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/pkg/pool"
@@ -126,7 +126,6 @@ func (p *Plugin) logCallback(event interface{}) {
// Serve serves the svc.
func (p *Plugin) Serve() chan error {
errCh := make(chan error, 2)
- go p.messages()
// run whole process in the goroutine
go func() {
// protect http initialization
@@ -169,9 +168,16 @@ func (p *Plugin) serve(errCh chan error) {
if p.cfg.EnableHTTP() {
if p.cfg.EnableH2C() {
- p.http = &http.Server{Handler: h2c.NewHandler(p, &http2.Server{}), ErrorLog: p.stdLog}
+ p.http = &http.Server{
+ Handler: h2c.NewHandler(p, &http2.Server{}),
+ ErrorLog: p.stdLog,
+ }
} else {
- p.http = &http.Server{Handler: p, ErrorLog: p.stdLog}
+ p.http = &http.Server{
+ Handler: p,
+ ErrorLog: p.stdLog,
+ ReadHeaderTimeout: time.Second,
+ }
}
}
@@ -210,6 +216,9 @@ func (p *Plugin) serve(errCh chan error) {
go func() {
p.serveFCGI(errCh)
}()
+
+ // read messages from the ws
+ go p.messages()
}
// Stop stops the http.
@@ -217,31 +226,24 @@ func (p *Plugin) Stop() error {
p.Lock()
defer p.Unlock()
- var err error
if p.fcgi != nil {
- err = p.fcgi.Shutdown(context.Background())
+ err := p.fcgi.Shutdown(context.Background())
if err != nil && err != http.ErrServerClosed {
p.log.Error("error shutting down the fcgi server", "error", err)
- // write error and try to stop other transport
- err = multierror.Append(err)
}
}
if p.https != nil {
- err = p.https.Shutdown(context.Background())
+ err := p.https.Shutdown(context.Background())
if err != nil && err != http.ErrServerClosed {
p.log.Error("error shutting down the https server", "error", err)
- // write error and try to stop other transport
- err = multierror.Append(err)
}
}
if p.http != nil {
- err = p.http.Shutdown(context.Background())
+ err := p.http.Close()
if err != nil && err != http.ErrServerClosed {
p.log.Error("error shutting down the http server", "error", err)
- // write error and try to stop other transport
- err = multierror.Append(err)
}
}
@@ -250,7 +252,7 @@ func (p *Plugin) Stop() error {
p.pool.Destroy(context.Background())
}
- return err
+ return nil
}
// ServeHTTP handles connection using set of middleware and pool PSR-7 server.