MCPcopy
hub / github.com/gofiber/fiber / shutdownServices

Method shutdownServices

services.go:116–143  ·  view source on GitHub ↗

shutdownServices Handles the shutdown process of services for the current application. Iterates over all the started services in reverse order and tries to terminate them, returning an error if any error occurs.

(ctx context.Context)

Source from the content-addressed store, hash-verified

114// Iterates over all the started services in reverse order and tries to terminate them,
115// returning an error if any error occurs.
116func (app *App) shutdownServices(ctx context.Context) error {
117 if app.state.ServicesLen() == 0 {
118 return nil
119 }
120
121 var errs []error
122 for key, srv := range app.state.Services() {
123 if srv == nil {
124 return fmt.Errorf("fiber: service %q is nil", key)
125 }
126 if err := ctx.Err(); err != nil {
127 // Context is canceled, do a best effort to terminate the services.
128 errs = append(errs, fmt.Errorf("service %s terminate: %w", srv.String(), err))
129 continue
130 }
131
132 err := srv.Terminate(ctx)
133 if err != nil {
134 // Best effort to terminate the services.
135 errs = append(errs, fmt.Errorf("service %s terminate: %w", srv.String(), err))
136 continue
137 }
138
139 // Remove the service from the State
140 app.state.deleteService(srv)
141 }
142 return errors.Join(errs...)
143}
144
145// logServices logs information about services and returns an error
146// if any configured service is nil.

Callers 5

Test_ShutdownServicesFunction · 0.95
initMethod · 0.95
Benchmark_ServicesMemoryFunction · 0.80

Calls 7

ServicesLenMethod · 0.80
ServicesMethod · 0.80
deleteServiceMethod · 0.80
ErrorfMethod · 0.65
ErrMethod · 0.65
StringMethod · 0.65
TerminateMethod · 0.65