Closed WyntersN closed 2 years ago
Hello @WyntersN ,
I ran a simple example of your case:
package main
import (
"net/http"
"time"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
app.Get("/", handler)
srv := &http.Server{
Addr: ":8083",
ReadTimeout: 60 * time.Second,
WriteTimeout: 120 * time.Second,
}
app.Run(iris.Server(srv))
}
func handler(ctx iris.Context) {
time.Sleep(15 * time.Second)
ctx.WriteString("OK")
}
And it does NOT fire a timeout error on 10 seconds. So timeouts are set correctly. Could you please post a full producable example? Because I can't see the issue here.
Thank you for your reply. Sorry to have kept your waiting. @kataras I'd be absolutely delighted to IRIS one's pygmy effort
package main
import (
"oa_iris/router"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
router.RouteApi(app)
service.LogInfo.Println("Api Reg")
//router
app.Party("/api")
{
router.RouteApi(app)
service.LogInfo.Println("Api reg")
}
app.Party("/admin")
{
router.RouteAdmin(app)
service.LogInfo.Println("Admin reg")
}
srv := &http.Server{
Addr: cf.Domain,
ReadTimeout: 60 * time.Second,
WriteTimeout: 120 * time.Second,
}
err := app.Run(iris.Server(srv))
if err != nil {
service.LogError.Fatalf("IRIS close %s", err)
}
}
package router
import (
"oa_iris/app/api"
v1App "oa_iris/app/api/controllers"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
)
func RouteApi(app *iris.Application) {
mvc.New(app.Party("/api/v1/login")).
Register(api.SessManager.Start).
Handle(new(v1App.AppLoginController))
mvc.New(app.Party("/api/v1/user", api.SessionLoginSignAuthApp)).
Register(api.SessManager.Start).
Handle(new(v1App.AppUserController))
}
func SessionLoginSignAuthApp(c iris.Context) {
token:= c.GetHeader("token")
if token != "" {
claim, err := common.ParseToken(token)
if err != nil {
c.JSON(err)
return
}
common.SessManager = SessManager.Start(c)
common.SessManager.Set("USER_ID",claim.uid)
c.Next()
return
}
c.JSON(err)
}
package router
import (
"oa_iris/app/admin/controllers"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
)
func RouteAdmin(app *iris.Application) {
mvc.New(app.Party("/admin/login")).
Handle(new(controllers.AdminController))
}
package app
import (
"oa_iris/app/api"
"oa_iris/app/api/model/app"
)
type AppUserController struct {
api.AppController
}
func (c *AppUserController) GetInfo() {
var retData api.ReturnJson
retData.Code , retData.Message,retData.Data = app.Info(c.Ctx)
c.Ctx.JSON(retData)
}
Q1: No SessionLoginSignAuthApp request timeout set success. Exist SessionLoginSignAuthApp request timeout set fail. How can I achieve it? Exist SessionLoginSignAuthApp request timeout set success Q2: user A(uid:10001) user B(uid:10002) user C(uid:10003) If user A get uid set time.Sleep 10s, user B get uid set time.Sleep 5s, user C get uid set time.Sleep 1s. Result use common.SessManager.Get("USER_ID"),User A B C uid become 10003 How to get IRIS uid correctly?
Hello @WyntersN, no worries about the delay, I late to answer too.
Request timeout doesn't mean that your functions (http handlers) will be canceled while they are running (refer to net/http documentation and go in general). To cancel operations you have to make use of the iris.Context.Done()
channel inside your services.
Do not fire SessionManager.Start
twice. Use the following snippet instead to work with session:
Register the handler
sess := sessions.New(sessions.Config{Cookie: cookieNameForSessionID, AllowReclaim: true})
app.Use(sess.Handler())
To set
session := sessions.Get(ctx)
session.Set("USER_ID", ...)
To retrieve
session := sessions.Get(ctx)
userID := session.Get("USER_ID")
Hello @kataras ,Thank you for your reply I need request timeout keep wait.However token verification implement ctx.Next(),function Main set request timeout fail.
Ctx.Next(),Set request timeout fail.
@kataras
@kataras
@kataras
Ctx.Next(),Set request timeout fail.
@kataras
@kataras
@kataras
@kataras
mvc.New(app.Party("/api/v1/user", api.SessionLoginSignAuthApp)).
Register(common.SessManager.Start).
Handle(new(v1App.AppUserController))
api.SessionLoginSignAuthApp
ctx.next() //Set request timeout fail.
@kataras
Hello @WyntersN, could you please provide me a complete example (source code in the comments) than I can copy-paste and re-produce the issue you mention? Thank you a lot
Describe the issue you are facing or ask for help
HTTP set Read 60s
HTTP set Write 120s
iris run 8803
http request
http request time
http timeout still 10s