Skip to content

Commit

Permalink
Fix ctx issues
Browse files Browse the repository at this point in the history
  • Loading branch information
infogulch committed Mar 11, 2024
1 parent e91291c commit df4cd8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ var nextInstanceIdentity atomic.Int64

type xinstance struct {
Config
id int64
ctx context.Context
id int64

stats InstanceStats
routes []InstanceRoute
Expand Down Expand Up @@ -215,7 +214,7 @@ var (

func (server *xinstance) ServeHTTP(w http.ResponseWriter, r *http.Request) {
select {
case <-server.ctx.Done():
case <-server.Ctx.Done():
server.Logger.Error("received request after xtemplate instance cancelled", slog.String("method", r.Method), slog.String("path", r.URL.Path))
http.Error(w, "server stopped", http.StatusInternalServerError)
return
Expand Down
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func (x *xserver) Reload() error {
}

var newcancel func()
x.config.Ctx, newcancel = context.WithCancel(x.config.Ctx)

var new_ *xinstance
{
var err error
new_, err = x.config.instance()
config := x.config
config.Ctx, newcancel = context.WithCancel(x.config.Ctx)
new_, err = config.instance()
if err != nil {
if newcancel != nil {
newcancel()
Expand Down
6 changes: 3 additions & 3 deletions tplcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func (f flushContext) Repeat(max_ ...int) <-chan int {
select {
case <-f.requestCtx.Done():
break loop
case <-f.server.ctx.Done():
case <-f.server.Ctx.Done():
break loop
case c <- i:
}
Expand All @@ -408,7 +408,7 @@ func (f flushContext) Sleep(ms int) (string, error) {
case <-time.After(time.Duration(ms) * time.Millisecond):
case <-f.requestCtx.Done():
return "", ReturnError{}
case <-f.server.ctx.Done():
case <-f.server.Ctx.Done():
return "", ReturnError{}
}
return "", nil
Expand All @@ -420,7 +420,7 @@ func (f flushContext) Block() (string, error) {
select {
case <-f.requestCtx.Done():
return "", ReturnError{}
case <-f.server.ctx.Done():
case <-f.server.Ctx.Done():
return "", nil
}
}
Expand Down

0 comments on commit df4cd8b

Please sign in to comment.