# Failed to connect to 127.0.0.1: Cannot assign requested address

**URL:** <https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320>\
**Category:** Elasticsearch\
**Created:** [October 11, 2012, 3:43pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320 "2012-10-11T15:43:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Rode](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Martin\_Rode](https://discuss.elastic.co/u/Martin_Rode)\
**Post date:** [October 11, 2012, 3:43pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/1 "2012-10-11T15:43:32Z")

</div>

Hi everybody,

I am testing elasticsearch since a while and all the sudden today, I am  
getting a weird error without having changed anything.

My PHP script indexes ~ 180k documents, and currently stops reliably after  
about 40k - 50k documents with the error message mentioned in the subject.

There is nothing in the elasticsearch.log.

On the PHP side I am using curl to connect to the service. I do one request  
per document, so it works fine for the first 40k or so docs.

This error does not happen on the same document, but very reliably after  
40k - 50k docs, after I deleted and re-created the index and even restartet  
the ES service.

Previously I have used "localhost:9200" as the address and changed it to  
127.0.0.1, which did not fix the problem.

I am using the ES version 0.19.8 on Debian (stock Debian install with ICU  
plugin).

Any ideas?

Thx  
Martin

--

---

<div class="post-metadata">

**Author:** ![drewr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewr/32/7803_2.png) [@drewr](https://discuss.elastic.co/u/drewr)\
**Post date:** [October 11, 2012, 10:17pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/2 "2012-10-11T22:17:21Z")

</div>

Martin Rode wrote:

> I am testing elasticsearch since a while and all the sudden today, I am  
> getting a weird error without having changed anything.
> 
> My PHP script indexes ~ 180k documents, and currently stops reliably after  
> about 40k - 50k documents with the error message mentioned in the subject.
> 
> There is nothing in the elasticsearch.log.
> 
> On the PHP side I am using curl to connect to the service. I do one request  
> per document, so it works fine for the first 40k or so docs.
> 
> This error does not happen on the same document, but very reliably after  
> 40k - 50k docs, after I deleted and re-created the index and even restartet  
> the ES service.

Can you give us an example of the error you're seeing?

-Drew

--

---

<div class="post-metadata">

**Author:** ![Martin\_Rode](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Martin\_Rode](https://discuss.elastic.co/u/Martin_Rode)\
**Post date:** [October 12, 2012, 1:26pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/3 "2012-10-12T13:26:57Z")

</div>

Drew, what do you mean?

CURL cannot connect to the elasticsearch server and says:

Could not read from [http://127.0.0.1:9200/easydb/bilder/43470](http://127.0.0.1:9200/easydb/bilder/43470) (0): Failed  
to connect to 127.0.0.1: Cannot assign requested address  
\*  
\*

On Friday, October 12, 2012 12:21:21 AM UTC+2, Drew Raines wrote:

> Martin Rode wrote:
> 
> > I am testing elasticsearch since a while and all the sudden today, I am  
> > getting a weird error without having changed anything.
> > 
> > My PHP script indexes ~ 180k documents, and currently stops reliably  
> > after  
> > about 40k - 50k documents with the error message mentioned in the  
> > subject.
> > 
> > There is nothing in the elasticsearch.log.
> > 
> > On the PHP side I am using curl to connect to the service. I do one  
> > request  
> > per document, so it works fine for the first 40k or so docs.
> > 
> > This error does not happen on the same document, but very reliably after  
> > 40k - 50k docs, after I deleted and re-created the index and even  
> > restartet  
> > the ES service.
> 
> Can you give us an example of the error you're seeing?
> 
> -Drew

--

---

<div class="post-metadata">

**Author:** ![Mohamed\_Lrhazi](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mohamed\_Lrhazi](https://discuss.elastic.co/u/Mohamed_Lrhazi)\
**Post date:** [October 12, 2012, 1:45pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/4 "2012-10-12T13:45:23Z")

</div>

I am using pyes, instead of PHP/curl... and I was get this error after a  
while of heavy indexing:

pyes.exceptions.NoServerAvailable

Google that error instead... I believe it's the same resource limits  
issue...

In my case, I added code to simply sleep for 60 seconds  
after every 500,000 documents indexed... to tell the cluster relax a bit 🙂

Thanks,  
Mohamed.

On Friday, October 12, 2012 9:26:57 AM UTC-4, Martin Rode wrote:

> Drew, what do you mean?
> 
> CURL cannot connect to the elasticsearch server and says:
> 
> Could not read from [http://127.0.0.1:9200/easydb/bilder/43470](http://127.0.0.1:9200/easydb/bilder/43470) (0): Failed  
> to connect to 127.0.0.1: Cannot assign requested address  
> \*  
> \*
> 
> On Friday, October 12, 2012 12:21:21 AM UTC+2, Drew Raines wrote:
> 
> > Martin Rode wrote:
> > 
> > > I am testing elasticsearch since a while and all the sudden today, I am  
> > > getting a weird error without having changed anything.
> > > 
> > > My PHP script indexes ~ 180k documents, and currently stops reliably  
> > > after  
> > > about 40k - 50k documents with the error message mentioned in the  
> > > subject.
> > > 
> > > There is nothing in the elasticsearch.log.
> > > 
> > > On the PHP side I am using curl to connect to the service. I do one  
> > > request  
> > > per document, so it works fine for the first 40k or so docs.
> > > 
> > > This error does not happen on the same document, but very reliably  
> > > after  
> > > 40k - 50k docs, after I deleted and re-created the index and even  
> > > restartet  
> > > the ES service.
> > 
> > Can you give us an example of the error you're seeing?
> > 
> > -Drew

--

---

<div class="post-metadata">

**Author:** ![drewr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drewr/32/7803_2.png) [@drewr](https://discuss.elastic.co/u/drewr)\
**Post date:** [October 12, 2012, 2:29pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/5 "2012-10-12T14:29:27Z")

</div>

Martin Rode wrote:

> Drew, what do you mean?

You had given us a description of a problem with no details, but this  
looks helpful:

> CURL cannot connect to the elasticsearch server and says:
> 
> Could not read from [http://127.0.0.1:9200/easydb/bilder/43470](http://127.0.0.1:9200/easydb/bilder/43470) (0): Failed  
> to connect to 127.0.0.1: Cannot assign requested address

Is the ES JVM dying somehow? This suggests that it's not listening  
anymore. And if so, you really don't see anything in the log? Try  
setting rootLogger to DEBUG in config/logging.yml to see if anything  
appears in the log then.

-Drew

--

---

<div class="post-metadata">

**Author:** ![Garth](https://avatars.discourse-cdn.com/v4/letter/g/ba9def/32.png) [@Garth](https://discuss.elastic.co/u/Garth)\
**Post date:** [October 12, 2012, 2:37pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/6 "2012-10-12T14:37:12Z")

</div>

By chance does your server have selinux and if so did it get changed to  
enabled?

On Thursday, October 11, 2012 11:43:32 AM UTC-4, Martin Rode wrote:

> Hi everybody,
> 
> I am testing elasticsearch since a while and all the sudden today, I am  
> getting a weird error without having changed anything.
> 
> My PHP script indexes ~ 180k documents, and currently  
> stops reliably after about 40k - 50k documents with the error message  
> mentioned in the subject.
> 
> There is nothing in the elasticsearch.log.
> 
> On the PHP side I am using curl to connect to the service. I do one  
> request per document, so it works fine for the first 40k or so docs.
> 
> This error does not happen on the same document, but very reliably after  
> 40k - 50k docs, after I deleted and re-created the index and even restartet  
> the ES service.
> 
> Previously I have used "localhost:9200" as the address and changed it to  
> 127.0.0.1, which did not fix the problem.
> 
> I am using the ES version 0.19.8 on Debian (stock Debian install with ICU  
> plugin).
> 
> Any ideas?
> 
> Thx  
> Martin

--

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [October 20, 2012, 5:34am UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/7 "2012-10-20T05:34:45Z")

</div>

You did not set the SO\_REUSEADDR flag, so after "40k -50k documents", you  
have forced your system to ran out of sockets. See  
also [PHP: socket\_set\_option - Manual](http://php.net/manual/de/function.socket-set-option.php)

Jörg

On Thursday, October 11, 2012 5:43:32 PM UTC+2, Martin Rode wrote:

> Hi everybody,
> 
> I am testing elasticsearch since a while and all the sudden today, I am  
> getting a weird error without having changed anything.
> 
> My PHP script indexes ~ 180k documents, and currently  
> stops reliably after about 40k - 50k documents with the error message  
> mentioned in the subject.
> 
> There is nothing in the elasticsearch.log.
> 
> On the PHP side I am using curl to connect to the service. I do one  
> request per document, so it works fine for the first 40k or so docs.
> 
> This error does not happen on the same document, but very reliably after  
> 40k - 50k docs, after I deleted and re-created the index and even restartet  
> the ES service.
> 
> Previously I have used "localhost:9200" as the address and changed it to  
> 127.0.0.1, which did not fix the problem.
> 
> I am using the ES version 0.19.8 on Debian (stock Debian install with ICU  
> plugin).
> 
> Any ideas?
> 
> Thx  
> Martin

--

---

<div class="post-metadata">

**Author:** ![tbrianjones](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbrianjones/32/1402_2.png) [@tbrianjones](https://discuss.elastic.co/u/tbrianjones)\
**Post date:** [February 6, 2013, 8:14am UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/8 "2013-02-06T08:14:59Z")

</div>

I was encountering the same problem using cURL in PHP. I was opening and closing a cURL connection with each request to Elasticsearch, and was making hundreds of thousands of requests from the same PHP process.

$this-\>Curl = curl\_init();  
// make requests  
curl\_close( $this-\>Curl );

When I rewrote my class to use the same cURL connection instance for every request, this problem went away. ( eg. I never call curl\_close() in my script, and use $this-\>Curl for every request ).

I do not know what is limiting the number of cURL connections I'm able to open and close in a single PHP thread. Perhaps someone else can shine some light on this.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 6, 2013, 12:44pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/9 "2013-02-06T12:44:56Z")

</div>

As said, that is very basic to socket programming. Operation systems  
keep socket addresses reserved after being closed for some minutes, in  
order to be prepared for reuse at reopening (TCP state CLOSE\_WAIT).  
Therefore, you should use persistent connections (HTTP keepalive or  
SO\_REUSEADDR), otherwise you will quickly consume all the socket  
addresses after some thousands request open/close cycles. Note that  
socket addresses are usually 16 bit wide, and for user space, you can  
go up to around a number of 40-50k sockets totally.

Jörg

Am 06.02.13 09:15, schrieb tbrianjones:

> I do not know what is limiting the number of cURL connections I'm able to  
> open and close in a single PHP thread. Perhaps someone else can shine some  
> light on this.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:52am UTC](https://discuss.elastic.co/t/failed-to-connect-to-127-0-0-1-cannot-assign-requested-address/9320/10 "2017-07-06T02:52:47Z")

</div>


