Skip to content

Commit

Permalink
Catch concurrent map read writes in gin
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrenne committed Sep 26, 2019
1 parent ee8a187 commit e4dbdf9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/ginServer/ginServerHelpers.go
Expand Up @@ -28,7 +28,14 @@ type LocaleLanguage struct {
Language string
}

func GetSessionKey(c *gin.Context, key string) string {
func GetSessionKey(c *gin.Context, key string) (sessionKey string) {
//https://github.com/gin-gonic/gin/issues/700
// defer needed to catch session.Get concurrent map read write.
defer func() {
if r := recover(); r != nil {
return
}
}()
session := sessions.Default(c)
if strings.Contains(c.Request.Host, ".com") {
session.Options(sessions.Options{MaxAge: 86400 * serverSettings.WebConfig.Application.SessionExpirationDays,
Expand All @@ -37,9 +44,11 @@ func GetSessionKey(c *gin.Context, key string) string {
}
value := session.Get(key)
if value == nil {
return ""
sessionKey = ""
return
} else {
return session.Get(key).(string)
sessionKey = session.Get(key).(string)
return
}
}

Expand Down

0 comments on commit e4dbdf9

Please sign in to comment.