fix a panic error
update gin-go
This commit is contained in:
parent
e1b4f21e00
commit
86f3e62aa8
5 changed files with 19 additions and 9 deletions
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/lbryio/reflector.go/meta"
|
"github.com/lbryio/reflector.go/meta"
|
||||||
"github.com/lbryio/reflector.go/reflector"
|
"github.com/lbryio/reflector.go/reflector"
|
||||||
"github.com/lbryio/reflector.go/server/http"
|
"github.com/lbryio/reflector.go/server/http"
|
||||||
http32 "github.com/lbryio/reflector.go/server/http3"
|
"github.com/lbryio/reflector.go/server/http3"
|
||||||
"github.com/lbryio/reflector.go/server/peer"
|
"github.com/lbryio/reflector.go/server/peer"
|
||||||
"github.com/lbryio/reflector.go/store"
|
"github.com/lbryio/reflector.go/store"
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func reflectorCmd(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
defer peerServer.Shutdown()
|
defer peerServer.Shutdown()
|
||||||
|
|
||||||
http3PeerServer := http32.NewServer(underlyingStoreWithCaches, requestQueueSize)
|
http3PeerServer := http3.NewServer(underlyingStoreWithCaches, requestQueueSize)
|
||||||
err = http3PeerServer.Start(":" + strconv.Itoa(http3PeerPort))
|
err = http3PeerServer.Start(":" + strconv.Itoa(http3PeerPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -162,7 +162,7 @@ func initUpstreamStore() store.BlobStore {
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
})
|
})
|
||||||
case "http3":
|
case "http3":
|
||||||
s = http32.NewStore(http32.StoreOpts{
|
s = http3.NewStore(http3.StoreOpts{
|
||||||
Address: upstreamReflector,
|
Address: upstreamReflector,
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
})
|
})
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -12,7 +12,7 @@ require (
|
||||||
github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2
|
github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2
|
||||||
github.com/davecgh/go-spew v1.1.1
|
github.com/davecgh/go-spew v1.1.1
|
||||||
github.com/ekyoung/gin-nice-recovery v0.0.0-20160510022553-1654dca486db
|
github.com/ekyoung/gin-nice-recovery v0.0.0-20160510022553-1654dca486db
|
||||||
github.com/gin-gonic/gin v1.7.1
|
github.com/gin-gonic/gin v1.7.2
|
||||||
github.com/go-sql-driver/mysql v1.6.0
|
github.com/go-sql-driver/mysql v1.6.0
|
||||||
github.com/gogo/protobuf v1.2.1
|
github.com/gogo/protobuf v1.2.1
|
||||||
github.com/golang/protobuf v1.5.2
|
github.com/golang/protobuf v1.5.2
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -134,8 +134,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
github.com/gin-gonic/gin v1.7.1 h1:qC89GU3p8TvKWMAVhEpmpB2CIb1hnqt2UdKZaP93mS8=
|
github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA=
|
||||||
github.com/gin-gonic/gin v1.7.1/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
|
||||||
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||||
github.com/go-errors/errors v1.1.1 h1:ljK/pL5ltg3qoN+OtN6yCv9HWSfMwxSx90GJCZQxYNg=
|
github.com/go-errors/errors v1.1.1 h1:ljK/pL5ltg3qoN+OtN6yCv9HWSfMwxSx90GJCZQxYNg=
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/lbryio/lbry.go/v2/extras/errors"
|
"github.com/lbryio/lbry.go/v2/extras/errors"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) getBlob(c *gin.Context) {
|
func (s *Server) getBlob(c *gin.Context) {
|
||||||
|
@ -22,6 +23,11 @@ func (s *Server) getBlob(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) HandleGetBlob(c *gin.Context) {
|
func (s *Server) HandleGetBlob(c *gin.Context) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
log.Errorf("Recovered from panic: %v", r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
hash := c.Query("hash")
|
hash := c.Query("hash")
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,15 @@ func (s *Server) Shutdown() {
|
||||||
// Start starts the server listener to handle connections.
|
// Start starts the server listener to handle connections.
|
||||||
func (s *Server) Start(address string) error {
|
func (s *Server) Start(address string) error {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
router := gin.Default()
|
router := gin.New()
|
||||||
router.GET("/blob", s.getBlob)
|
router.Use(gin.Logger())
|
||||||
router.HEAD("/blob", s.hasBlob)
|
|
||||||
// Install nice.Recovery, passing the handler to call after recovery
|
// Install nice.Recovery, passing the handler to call after recovery
|
||||||
router.Use(nice.Recovery(s.recoveryHandler))
|
router.Use(nice.Recovery(s.recoveryHandler))
|
||||||
|
router.GET("/blob", s.getBlob)
|
||||||
|
router.GET("/", func(c *gin.Context) {
|
||||||
|
panic("woops")
|
||||||
|
})
|
||||||
|
router.HEAD("/blob", s.hasBlob)
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: address,
|
Addr: address,
|
||||||
Handler: router,
|
Handler: router,
|
||||||
|
|
Loading…
Reference in a new issue