MCPcopy
hub / github.com/fvbock/endless / hammerTime

Method hammerTime

endless.go:398–419  ·  view source on GitHub ↗

* hammerTime forces the server to shutdown in a given timeout - whether it finished outstanding requests or not. if Read/WriteTimeout are not set or the max header size is very big a connection could hang... srv.Serve() will not return until all connections are served. this will unblock the srv.wg.

(d time.Duration)

Source from the content-addressed store, hash-verified

396return.
397*/
398func (srv *endlessServer) hammerTime(d time.Duration) {
399 defer func() {
400 // we are calling srv.wg.Done() until it panics which means we called
401 // Done() when the counter was already at 0 and we're done.
402 // (and thus Serve() will return and the parent will exit)
403 if r := recover(); r != nil {
404 log.Println("WaitGroup at 0", r)
405 }
406 }()
407 if srv.getState() != STATE_SHUTTING_DOWN {
408 return
409 }
410 time.Sleep(d)
411 log.Println("[STOP - Hammer Time] Forcefully shutting down parent")
412 for {
413 if srv.getState() == STATE_TERMINATE {
414 break
415 }
416 srv.wg.Done()
417 runtime.Gosched()
418 }
419}
420
421func (srv *endlessServer) fork() (err error) {
422 runningServerReg.Lock()

Callers 2

handleSignalsMethod · 0.95
shutdownMethod · 0.95

Calls 1

getStateMethod · 0.95

Tested by

no test coverage detected