mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-05 12:23:03 +02:00
core: use context.WithoutCancel (#4959)
This commit is contained in:
parent
6b245d2a24
commit
76862c2fe8
2 changed files with 1 additions and 25 deletions
|
@ -64,25 +64,3 @@ func (mc *mergedCtx) Value(key interface{}) interface{} {
|
||||||
}
|
}
|
||||||
return mc.doneCtx.Value(key)
|
return mc.doneCtx.Value(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
type onlyValues struct {
|
|
||||||
context.Context
|
|
||||||
}
|
|
||||||
|
|
||||||
// OnlyValues returns a derived context that removes deadlines and cancellation,
|
|
||||||
// but keeps values.
|
|
||||||
func OnlyValues(ctx context.Context) context.Context {
|
|
||||||
return onlyValues{ctx}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o onlyValues) Deadline() (time.Time, bool) {
|
|
||||||
return time.Time{}, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o onlyValues) Done() <-chan struct{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o onlyValues) Err() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/pkg/contextutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeWithGracefulStop serves the HTTP listener until ctx.Done(), and then gracefully stops and waits for gracefulTimeout
|
// ServeWithGracefulStop serves the HTTP listener until ctx.Done(), and then gracefully stops and waits for gracefulTimeout
|
||||||
|
@ -17,7 +15,7 @@ func ServeWithGracefulStop(ctx context.Context, handler http.Handler, li net.Lis
|
||||||
// create a context that will be used for the http requests
|
// create a context that will be used for the http requests
|
||||||
// it will only be cancelled when baseCancel is called but will
|
// it will only be cancelled when baseCancel is called but will
|
||||||
// preserve the values from ctx
|
// preserve the values from ctx
|
||||||
baseCtx, baseCancel := context.WithCancelCause(contextutil.OnlyValues(ctx))
|
baseCtx, baseCancel := context.WithCancelCause(context.WithoutCancel(ctx))
|
||||||
|
|
||||||
srv := http.Server{
|
srv := http.Server{
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue