-
Notifications
You must be signed in to change notification settings - Fork 176
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
use of closed network connection #31
Comments
I could not replicate your error. I tried a version of your code (see below) that I tested by
Maybe...
Here's the middleware I used for testing: package midware
import (
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/alexedwards/scs"
"fmt"
"github.com/alexedwards/scs/stores/redisstore"
"github.com/garyburd/redigo/redis"
"time"
"net/http/httputil"
)
type SessionInitializeConfig struct {
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// the scs session manager
SessionManager *scs.Manager
}
var (
DefaultSessionInitializeConfig = SessionInitializeConfig{
Skipper: middleware.DefaultSkipper,
// hardcoded encryption key for testing - not production
// https://github.com/alexedwards/scs
// to create random key: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang
SessionManager: scs.NewCookieManager("u46IpCV9y5Vlur8YvODJEhgOY8m9JVE4"),
}
)
func SessionInitialize() echo.MiddlewareFunc {
return SessionInitializeWithConfig(DefaultSessionInitializeConfig)
}
func NewSessionManagerRedis() *scs.Manager {
engine := redisstore.New(
&redis.Pool{
MaxIdle: 10,
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", "127.0.0.1:6379")
},
},
)
sessionManager := scs.NewManager(engine)
sessionManager.Name("sessionid")
sessionManager.Path("/")
sessionManager.Lifetime(60 * time.Minute)
sessionManager.Secure(false)
sessionManager.HttpOnly(true)
sessionManager.IdleTimeout(20 * time.Minute)
sessionManager.Persist(true)
return sessionManager
}
func SessionInitializeWithConfig(config SessionInitializeConfig) echo.MiddlewareFunc {
// Defaults
if config.Skipper == nil {
config.Skipper = DefaultSessionInitializeConfig.Skipper
}
if config.SessionManager == nil {
config.SessionManager = DefaultSessionInitializeConfig.SessionManager
}
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if config.Skipper(c) {
return next(c)
}
session := config.SessionManager.Load(c.Request())
session.Touch(c.Response())
// NOTE: this is enough to initialize the cookie
// return next(c)
// ----------------
// Begin tests
counter, err := session.GetInt64("counter")
if err != nil {
counter = 0
}
counter++
session.PutInt64(c.Response(), "counter", counter)
session.PutString(c.Response(), "count-as-string", fmt.Sprintf("count is %d", counter))
fmt.Printf("%+v\n", session)
requestDump, err := httputil.DumpRequest(c.Request(), true)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(requestDump))
// End tests
// ----------------
return next(c)
}
}
} Create the redis store and invoke with sessionManager := midware.NewSessionManagerRedis()
e.Use(midware.SessionInitializeWithConfig(midware.SessionInitializeConfig{SessionManager: sessionManager})) |
Also because the |
I haven't been able to replicate this either. Is it still causing a problem? |
Closing due to age and lack of further information. Please reopen if it continues to be a problem with the latest version. |
I use SCS to implement session functionality in the echo framework, but I delete the sessionid in cookie and then refresh the browser and output the error:
My code:
The text was updated successfully, but these errors were encountered: