owasp-amass/amass · critical

failed to create the API server

Error message

failed to create the API server

What it means

After building the dispatcher, NewEngine calls server.NewServer to create the API server. If it errors or returns nil, the engine shuts down the dispatcher and session manager and fails startup with this error.

Source

Thrown at engine/engine.go:56

		l = slog.New(slog.NewTextHandler(os.Stdout, nil))
	}

	reg := registry.NewRegistry(l)
	mgr := sessions.NewManager(l, reg)
	if mgr == nil {
		return nil, errors.New("failed to create the session manager")
	}

	dis := dispatcher.NewDispatcher(l, reg, mgr)
	if err := plugins.LoadAndStartPlugins(reg); err != nil {
		return nil, err
	}

	srv, err := server.NewServer(l, dis, mgr)
	if err != nil || srv == nil {
		dis.Shutdown()
		mgr.Shutdown()
		return nil, errors.New("failed to create the API server")
	}

	ch := make(chan error, 1)
	go func(errch chan error) { errch <- srv.Start() }(ch)

	t := time.NewTimer(3 * time.Second)
	defer t.Stop()

	select {
	case err := <-ch:
		if err != nil {
			_ = srv.Shutdown()
			dis.Shutdown()
			mgr.Shutdown()
			return nil, err
		}
	case <-t.C:
		// If the server does not return an error within 3 seconds, we assume it started successfully

View on GitHub (pinned to 79299dce87)

Solutions

  1. Check the API server configuration (address, port, TLS settings) for invalid values
  2. Look at any log output from server.NewServer for the root cause before this generic error
  3. Verify the server package builds and its constructor matches the call site
  4. Ensure the port is free and not blocked by permissions
Defensive patterns

Strategy: try-catch

Validate before calling

if cfg.APIAddr == "" || cfg.APIPort == 0 {
    return errors.New("API server address/port must be configured")
}

Try / catch

eng, err := NewEngine(cfg)
if err != nil {
    log.Fatalf("engine initialization failed: %v", err)
}
// note: NewEngine already shuts down dispatcher and manager on this error

Prevention

When it happens

Trigger: server.NewServer(l, dis, mgr) returns an error or a nil server during NewEngine, e.g. invalid configuration for the HTTP server, port binding setup failure surfaced at construction, or internal nil checks.

Common situations: Bad API server configuration (invalid address/port values), a broken build of the api/server package, or version drift between the server constructor signature and its caller.

Related errors


AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/fc22fd5dc1ca5147. Report an issue: GitHub.