-
Notifications
You must be signed in to change notification settings - Fork 974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port is not properly set in requests, causing No alive nodes found in your cluster #993
Comments
@larsnystrom I'm trying to reproduce the issue but I don't see any issue. Did you try the following configuration? $client = ClientBuilder::create()
->setBasicAuthentication('user', 'pass')
->setHosts(['https://elastic.example.com:9243'])
->build(); or $client = ClientBuilder::create()
->setBasicAuthentication('user', 'pass')
->setHosts([
[
'host' => 'elastic.example.com',
'port' => 9243,
'scheme' => 'https'
]
])
->build(); Let me know, thanks! |
It does not matter which of those configurations you use. Here is a test script as well as some actual output when I ran it. The only thing I have changed here is the domain name ( I have added both of the configuration variations to the test script so that it is easy to switch between them, but as you can see I'm only using one of them at a time.
Save it as
The issue here is |
@larsnystrom ok, this is basically the opposite issue of what @afrozenpeach said here regarding the port specified in |
There is a load balancer/proxy in front of the Elasticsearch server, but I don't know its name. That's where the request is dropped due to the missing port. An option seems reasonable. Personally I think it should default to And sorry if I came off a bit harsh at the beginning of this issue. |
@larsnystrom thanks for your feedback! I'll add a I'm preparing a PR for this and I'll ask you to review, thanks again! |
@larsnystrom I just created PR #997, if you have time can you review it? Thanks! |
Summary of problem or feature request
The elasticsearch-php library does not set the correct Host header when using a custom port.
I was getting "No alive nodes found in your cluster" when performing a query using elasticsearch-php, but everything was working fine when doing the same request using curl on the command line.
After setting
CURLOPT_VERBOSE => 1
in the script and using the-v
flag in the CLI, I noticed that the HTTPHost
header was what differed between the elasticserach-php request and the CLI request. The CLI request set the Host header toelastic.example.com:9243
but the elasticsearch-php client set the Host header toelastic.example.com
, even though the request was still made to the correct port on the TCP layer.The missing port number in the Host header led to the server sending an empty response (cURL error 52: Empty reply from server).
The elasticsearch cluster is running HTTPS, on port 9243, with HTTP basic auth. This bug applies both when configuring the host (
ClientBuilder::setHosts()
) using a string such ashttps://user:[email protected]:9243
as well as when configuring the host with an array containing the same information in separate fields (scheme, host, port, etc).Edit: After looking a bit closer at the other tickets (and having lunch...), I realized that this is closely related to #925, which also explains that this bug was introduced in #782. The author of #782 says that "having the port in the host header is optional", but as @polyfractal says a bit earlier in the same thread this is not really the case if you read the RFC. Elasticsearch uses the HTTP protocol which means the implied port will be 80, or in the case of HTTPS 443. You cannot omit it and still stay compliant with HTTP/S, and if you're not compliant with HTTP/S then all bets are off when it comes to configuration of proxies, web servers, etc, which invalidates the reason for introducing the PR in the first place.
Code snippet of problem
The problem is fixed by changing line 208 in
Elasticsearch\Connections\Connection
(in theperformRequest
method) fromto
System details
The text was updated successfully, but these errors were encountered: