func()

in lambda/rapidcore/server.go [388:452]


func (s *Server) Reset(reason string, timeoutMs int64) (*statejson.ResetDescription, error) {
	// pass reset to rapid
	reset := &interop.Reset{
		Reason:     reason,
		DeadlineNs: deadlineNsFromTimeoutMs(timeoutMs),
	}
	go func() {
		select {
		case s.interruptedResponseChan <- reset:
			<-s.interruptedResponseChan // wait for response streaming metrics being added to reset struct
			s.sandboxContext.SetInvokeResponseMetrics(reset.InvokeResponseMetrics)
		default:
		}

		resetSuccess, resetFailure := s.sandboxContext.Reset(reset)
		s.Clear() // clear server state to prepare for new invokes
		s.setRapidPhase(phaseIdle)
		s.setRuntimeState(runtimeNotStarted)

		var meta interop.DoneMetadata
		if reset.InvokeResponseMetrics != nil && interop.IsResponseStreamingMetrics(reset.InvokeResponseMetrics) {
			meta.RuntimeTimeThrottledMs = reset.InvokeResponseMetrics.TimeShapedNs / int64(time.Millisecond)
			meta.RuntimeProducedBytes = reset.InvokeResponseMetrics.ProducedBytes
			meta.RuntimeOutboundThroughputBps = reset.InvokeResponseMetrics.OutboundThroughputBps
			meta.MetricsDimensions = interop.DoneMetadataMetricsDimensions{
				InvokeResponseMode: reset.InvokeResponseMode,
			}

			// These metrics aren't present in reset struct, therefore we need to get
			// them from s.sandboxContext.Reset()  response
			if resetFailure != nil {
				meta.RuntimeResponseLatencyMs = resetFailure.ResponseMetrics.RuntimeResponseLatencyMs
			} else {
				meta.RuntimeResponseLatencyMs = resetSuccess.ResponseMetrics.RuntimeResponseLatencyMs
			}
		}

		if resetFailure != nil {
			meta.ExtensionsResetMs = resetFailure.ExtensionsResetMs
			s.ResetDoneChan <- &interop.Done{ErrorType: resetFailure.ErrorType, Meta: meta}
		} else {
			meta.ExtensionsResetMs = resetSuccess.ExtensionsResetMs
			s.ResetDoneChan <- &interop.Done{ErrorType: resetSuccess.ErrorType, Meta: meta}
		}
	}()

	done := <-s.ResetDoneChan
	s.Release()

	if done.ErrorType != "" {
		return nil, errors.New(string(done.ErrorType))
	}

	return &statejson.ResetDescription{
		ExtensionsResetMs: done.Meta.ExtensionsResetMs,
		ResponseMetrics: statejson.ResponseMetrics{
			RuntimeResponseLatencyMs: done.Meta.RuntimeResponseLatencyMs,
			Dimensions: statejson.ResponseMetricsDimensions{
				InvokeResponseMode: statejson.InvokeResponseMode(
					done.Meta.MetricsDimensions.InvokeResponseMode,
				),
			},
		},
	}, nil
}