Merge pull request #19 from foomo/feature/contentserver-panic-fix

ContentServer Panic Fix
This commit is contained in:
Stefan Martinov 2019-09-07 09:44:35 +02:00 committed by GitHub
commit 130ab553e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

2
go.mod
View File

@ -12,3 +12,5 @@ require (
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.10.0
)
go 1.13

View File

@ -184,15 +184,7 @@ func (repo *Repo) GetContent(r *requests.Content) (c *content.SiteContent, err e
Log.Info("resolvecontent got status 404", zap.String("URI", r.URI))
c.Status = content.StatusNotFound
c.Dimension = r.Env.Dimensions[0]
}
Log.Debug("got content",
zap.Bool("resolved", resolved),
zap.String("resolvedURI", resolvedURI),
zap.String("resolvedDimension", resolvedDimension),
zap.String("nodeName", node.Name),
)
if !resolved {
Log.Debug("failed to resolve, falling back to default dimension",
zap.String("URI", r.URI),
zap.String("defaultDimension", r.Env.Dimensions[0]),
@ -200,6 +192,7 @@ func (repo *Repo) GetContent(r *requests.Content) (c *content.SiteContent, err e
// r.Env.Dimensions is validated => we can access it
resolvedDimension = r.Env.Dimensions[0]
}
// add navigation trees
for _, node := range r.Nodes {
if node.Dimension == "" {

View File

@ -84,6 +84,12 @@ func (s *socketServer) writeResponse(conn net.Conn, reply []byte) {
}
func (s *socketServer) handleConnection(conn net.Conn) {
defer func() {
if r := recover(); r != nil {
Log.Error("panic in handle connection", zap.String("error", fmt.Sprint(r)))
}
}()
Log.Debug("socketServer.handleConnection")
status.M.NumSocketsGauge.WithLabelValues(conn.RemoteAddr().String()).Inc()

View File

@ -1,6 +1,7 @@
package server
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
@ -28,6 +29,12 @@ func NewWebServer(path string, r *repo.Repo) http.Handler {
}
func (s *webServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recover(); r != nil {
Log.Error("panic in handle connection", zap.String("error", fmt.Sprint(r)))
}
}()
if r.Body == nil {
http.Error(w, "no body", http.StatusBadRequest)
return