mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-27 16:07:42 +08:00
Merge pull request #1636 from ipfs/fix/panic-ignore
recover and print panics that happen in API server
This commit is contained in:
@ -7,6 +7,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -103,6 +105,16 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Debug("Incoming API request: ", r.URL)
|
log.Debug("Incoming API request: ", r.URL)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
log.Error(r)
|
||||||
|
|
||||||
|
buf := make([]byte, 4096)
|
||||||
|
n := runtime.Stack(buf, false)
|
||||||
|
fmt.Fprintln(os.Stderr, string(buf[:n]))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if !allowOrigin(r, i.cfg) || !allowReferer(r, i.cfg) {
|
if !allowOrigin(r, i.cfg) || !allowReferer(r, i.cfg) {
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
w.Write([]byte("403 - Forbidden"))
|
w.Write([]byte("403 - Forbidden"))
|
||||||
|
Reference in New Issue
Block a user