{"record":{"id":"b9ca8d2080fc52d4","repo":"XTLS/Xray-core","slug":"no-target-server-found","errorCode":null,"errorMessage":"no target server found","messagePattern":"no target server found","errorType":"validation","errorClass":"errors.Error","httpStatus":null,"severity":"critical","filePath":"proxy/http/client.go","lineNumber":53,"sourceCode":"\tserver        *protocol.ServerSpec\n\tpolicyManager policy.Manager\n\theader        []*Header\n}\n\ntype h2Conn struct {\n\trawConn net.Conn\n\th2Conn  *http2.ClientConn\n}\n\nvar (\n\tcachedH2Mutex sync.Mutex\n\tcachedH2Conns map[net.Destination]h2Conn\n)\n\n// NewClient create a new http client based on the given config.\nfunc NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {\n\tif config.Server == nil {\n\t\treturn nil, errors.New(`no target server found`)\n\t}\n\tserver, err := protocol.NewServerSpecFromPB(config.Server)\n\tif err != nil {\n\t\treturn nil, errors.New(\"failed to get server spec\").Base(err)\n\t}\n\n\tv := core.MustFromContext(ctx)\n\treturn &Client{\n\t\tserver:        server,\n\t\tpolicyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),\n\t\theader:        config.Header,\n\t}, nil\n}\n\n// Process implements proxy.Outbound.Process. We first create a socket tunnel via HTTP CONNECT method, then redirect all inbound traffic to that tunnel.\nfunc (c *Client) Process(ctx context.Context, link *transport.Link, dialer internet.Dialer) error {\n\toutbounds := session.OutboundsFromContext(ctx)\n\tob := outbounds[len(outbounds)-1]","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/http/client.go#L35-L71","documentation":"The HTTP outbound (proxy/http, i.e. an HTTP CONNECT client) was constructed with a ClientConfig whose Server field is nil. NewClient requires a server spec (address+port of the HTTP proxy) before it can dial anything, so a nil server aborts handler creation.","triggerScenarios":"Outbound config with \"protocol\":\"http\" but missing settings.servers[] (or an empty array), or programmatic construction passing a ClientConfig without Server.","commonSituations":"JSON config typo (\"server\" instead of \"servers\"), empty servers list after templating/generation, version upgrade that renamed the field.","solutions":["Add settings.servers: [ { \"address\": \"proxy.example.com\", \"port\": 3128, \"users\": [...] } ] to the outbound","Verify field names against the current Xray HTTP outbound schema (it is an array named servers)","If building ClientConfig in Go, set .Server from a valid serializable server spec before NewClient"],"exampleFix":"// before\n{ \"protocol\": \"http\", \"settings\": {} }\n// after\n{ \"protocol\": \"http\", \"settings\": { \"servers\": [ { \"address\": \"proxy.example.com\", \"port\": 3128 } ] } }","handlingStrategy":"validation","validationCode":"```go\nif cfg.Server == nil {\n    return errors.New(\"http outbound requires settings.servers[0]\")\n}\nclient, err := http.NewClient(ctx, cfg)\n```","typeGuard":"```go\nfunc hasHTTPServer(cfg *http.ClientConfig) bool {\n    return cfg != nil && cfg.Server != nil\n}\n```","tryCatchPattern":null,"preventionTips":["Schema-validate outbound configs before start","Watch for field renames across Xray versions","Fail fast in config loaders on empty servers"],"tags":["http-outbound","config","validation","xray"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}