// Catch panics, usually caused by remote disconnects.
178387
func (c *MConnection) _recover() {
	if r := recover(); r != nil {
		err := cmn.ErrorWrap(r, "recovered panic in MConnection")
		c.stopForError(err)
	}
}
1326032
func (l *Logger) Panic(v ...interface{}) {
	s := fmt.Sprint(v...)
	l.Emit(1, s, nil)
	panic(s)
}
720366
func (we *WorkflowExecutor) HandleError() {
	if r := recover(); r != nil {
		_ = we.AddAnnotation(common.AnnotationKeyNodeMessage, fmt.Sprintf("%v", r))
		log.Fatalf("executor panic: %+v\n%s", r, debug.Stack())
	} else {
		if len(we.errors) > 0 {
			_ = we.AddAnnotation(common.AnnotationKeyNodeMessage, we.errors[0].Error())
		}
	}
}
955897
func (d SimpleDetector) Detect() (expired []string, err error) {
	return d.strategy.Expired(d.location, d.pool)
}
666022
func CatchAll(sigc chan os.Signal) {
	var handledSigs []os.Signal
	for _, s := range SignalMap {
		handledSigs = append(handledSigs, s)
	}
	signal.Notify(sigc, handledSigs...)
}
1199585
func (k *Kite) OnDisconnect(handler func(*Client)) {
	k.handlersMu.Lock()
	k.onDisconnectHandlers = append(k.onDisconnectHandlers, handler)
	k.handlersMu.Unlock()
}
458234
func (sd *defaultSlowDetector) Detect(eventCh <-chan *events.Envelope, errCh <-chan error) (<-chan *events.Envelope, <-chan error, slowDetectCh) {
	sd.logger.Println("[INFO] Start detecting slowConsumerAlert event")

	// Create new channel to pass producer
	eventCh_ := make(chan *events.Envelope)
	errCh_ := make(chan error)

	// doneCh is used to cancel sending data to
	// downstream process.
	sd.doneCh = make(chan struct{})

	// deteCh is used to send `slowConsumerAlert` event
	detectCh := make(slowDetectCh)

	// Detect from from trafficcontroller event messages
	go func() {
		defer close(eventCh_)
		for event := range eventCh {
			// Check nozzle can catch up firehose outputs speed.
			if isTruncated(event) {
				detectCh <- fmt.Errorf("doppler dropped messages from its queue because nozzle is slow")
			}

			select {
			case eventCh_ <- event:
			case <-sd.doneCh:
				// After doneCh is closed, sending event to downstream
				// is immediately stopped.
				return
			}

		}
	}()

	// Detect from websocket errors
	go func() {
		defer close(errCh_)
		for err := range errCh {
			switch t := err.(type) {
			case *websocket.CloseError:
				if t.Code == websocket.ClosePolicyViolation {
					// ClosePolicyViolation (1008)
					// indicates that an endpoint is terminating the connection
					// because it has received a message that violates its policy.
					//
					// This is a generic status code that can be returned when there is no
					// other more suitable status code (e.g., 1003 or 1009) or if there
					// is a need to hide specific details about the policy.
					//
					// http://tools.ietf.org/html/rfc6455#section-11.7
					detectCh <- fmt.Errorf(
						"websocket terminates the connection because connection is too slow (ClosePolicyViolation)")
				}
			}
			select {
			case errCh_ <- err:
			case <-sd.doneCh:
				// After doneCh is closed, sending events to downstream
				// is immediately stopped.
				return
			}

		}
	}()

	return eventCh_, errCh_, detectCh
}
1268897
func PanicHandlerFunc(h http.HandlerFunc, errH http.HandlerFunc) http.HandlerFunc {
	return PanicHandler(h, errH)
}
255543
func PanicFunc(err error, f fn, message string, args ...interface{}) {
	if err != nil {
		f()
		logger.Printf(message+"\n", args...)
		panic(err)
	}
}
680598
func (f *Forwarder) catchAll(ctx *authContext, w http.ResponseWriter, req *http.Request) (interface{}, error) {
	sess, err := f.getOrCreateClusterSession(*ctx)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	if err := f.setupForwardingHeaders(ctx, sess, req); err != nil {
		return nil, trace.Wrap(err)
	}
	sess.forwarder.ServeHTTP(w, req)
	return nil, nil
}
977691
func catchTerminate(shutdownCh chan struct{}) {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL)
	defer signal.Stop(sig)
	select {
	case <-shutdownCh:
		unlockEcho()
	case <-sig:
		unlockEcho()
	}
}
283248
func catchInterrupt(handler func()) {
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, interruptSignals()...)
	go func() {
		stopCalled := false
		for range sig {
			if !stopCalled {
				stopCalled = true
				handler()
			} else {
				os.Exit(2)
			}
		}
	}()
}
110452
func Panic(v ...interface{}) {
	s := fmt.Sprint(v...)
	log.Output(2, s)
	panic(s)
}
397767
func PanicHandler(h http.Handler, errH http.Handler) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		defer func() {
			if err := recover(); err != nil {
				if errH != nil {
					ew := &errResponseWriter{w, err}
					errH.ServeHTTP(ew, r)
				} else {
					http.Error(w, fmt.Sprintf("%s", err), http.StatusInternalServerError)
				}
			}
		}()

		// Call the protected handler
		h.ServeHTTP(w, r)
	}
}
1348877
func go_on_disconnect_callback(privateCtx unsafe.Pointer) C.int {
	log.Debug("go_on_disconnect_callback BEGIN")
	defer log.Debug("go_on_disconnect_callback END")
	context.lock.RLock()
	defer context.lock.RUnlock()

	// Get memif reference.
	ifIndex := int(uintptr(privateCtx))
	memif, exists := context.memifs[ifIndex]
	if !exists {
		// Already closed.
		return C.int(0)
	}

	// Stop polling the RX queues for interrupts.
	buf := make([]byte, 8)
	binary.PutUvarint(buf, 1)
	// - add an event
	_, err := syscall.Write(memif.stopQPollFd, buf[:])
	if err != nil {
		return C.int(ErrSyscall.Code())
	}
	// - wait
	memif.wg.Wait()
	// - remove the event
	_, err = syscall.Read(memif.stopQPollFd, buf[:])
	if err != nil {
		return C.int(ErrSyscall.Code())
	}

	// Call the user callback.
	if memif.callbacks.OnDisconnect != nil {
		memif.callbacks.OnDisconnect(memif)
	}

	// Close Rx/Tx queues.
	memif.closeQueues()

	return C.int(0)
}
1065979
func panicHandler(w http.ResponseWriter, r *http.Request, rcv interface{}) {
	ctx := r.Context()
	pe := &platform.Error{
		Code: platform.EInternal,
		Msg:  "a panic has occurred",
		Err:  fmt.Errorf("%v", rcv),
	}

	l := getPanicLogger()
	if entry := l.Check(zapcore.ErrorLevel, pe.Msg); entry != nil {
		entry.Stack = string(debug.Stack())
		entry.Write(zap.Error(pe.Err))
	}

	EncodeError(ctx, pe, w)
}
1267886
func panicToError(err *error) {
	if r := recover(); r != nil {
		switch t := r.(type) {
		case string:
			*err = errors.New(t)
		case error:
			*err = t
		default: // panic again if we don't know how to handle
			panic(r)
		}
	}
}