func Selfdestruct(limit float64) func(chi.Handler) chi.Handler {
	return func(next chi.Handler) chi.Handler {
		fn := func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
			if MemoryUsage() > limit {
				go selfdestruct(ctx, SignalSelfdestructGroup)
			}

			next.ServeHTTPC(ctx, w, r)
		}
		return chi.HandlerFunc(fn)
	}
}
// Selfdestruct is a middleware that terminates current process if system
// memory use exceeds the threshold set.
//
// Most common use case is automatic restart of leaky *cough*GCO*cough service
// all you need is this middleware and something that will start the process
// again after it's been terminated (docker --restart=always for example )
//
// OOMSelfdestruct accepts one parameter - a float64 defining a fraction of the
// system memory that can be used before process self-terminates using system
// signal (SIG_TERM).
// As long as the app handles shutdown gracefully on SIG_TERM it should just work
//
// Right now it relies on memory usage data provided by /proc/meminfo so it is
// Linux specific. For convenience (dev envs) it will do nothing on other archs
Selfdestruct is a middleware that terminates current process if system
memory use exceeds the threshold set.

Most common use case is automatic restart of leaky *cough*GCO*cough service
all you need is this middleware and something that will start the process
again after it's been terminated (docker --restart=always for example )

OOMSelfdestruct accepts one parameter - a float64 defining a fraction of the
system memory that can be used before process self-terminates using system
signal (SIG_TERM).
As long as the app handles shutdown gracefully on SIG_TERM it should just work

Right now it relies on memory usage data provided by /proc/meminfo so it is
Linux specific. For convenience (dev envs) it will do nothing on other archs
// Selfdestruct is a middleware that terminates current process if system // memory use exceeds the threshold set . // // Most common use case is automatic restart of leaky * cough * GCO * cough service // all you need is this middleware and something that will start the process // again after it ' s been terminated ( docker -- restart = always for example ) // // OOMSelfdestruct accepts one parameter - a float64 defining a fraction of the // system memory that can be used before process self - terminates using system // signal ( SIG_TERM ) . // As long as the app handles shutdown gracefully on SIG_TERM it should just work // // Right now it relies on memory usage data provided by / proc / meminfo so it is // Linux specific . For convenience ( dev envs ) it will do nothing on other archs
func Selfdestruct(limit float64) func(chi.Handler) chi.Handler {
	return func(next chi.Handler) chi.Handler {
		fn := func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
			if MemoryUsage() > limit {
				go selfdestruct(ctx, SignalSelfdestructGroup)
			}
			next.ServeHTTPC(ctx, w, r)
		}
		return chi.HandlerFunc(fn)
	}
}
func Selfdestruct ( limit float64 ) func ( chi . Handler ) chi . Handler { return func ( next chi . Handler ) chi . Handler { fn := func ( ctx context . Context , w http . ResponseWriter , r * http . Request ) { if MemoryUsage ( ) > limit { go selfdestruct ( ctx , SignalSelfdestructGroup ) } next . ServeHTTPC ( ctx , w , r ) } return chi . HandlerFunc ( fn ) } }
Selfdestruct is a middleware that terminates current process if system
memory use exceeds the threshold set.
Selfdestruct is a middleware that terminates current process if system memory use exceeds the threshold set .