# "java.net.ConnectException: Cannot assign requested address"

**URL:** <https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450>\
**Category:** Gatling (Open-Source)\
**Created:** [September 22, 2014, 5:13pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450 "2014-09-22T17:13:46Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Empty\_Account1](https://avatars.discourse-cdn.com/v4/letter/e/5f8ce5/32.png) [@Empty\_Account1](https://community.gatling.io/u/Empty_Account1)\
**Post date:** [September 22, 2014, 5:13pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/1 "2014-09-22T17:13:46Z")

</div>

Hi,

I am running tests on a m3.xlarge (4 CPU, 15GB RAM).

I am ramping up to 500rps for a period of 10 minutes.

rampUsersPerSec(1) to(500) during(10.minutes)

I have set my open-file limit to 65535

$ ulimit -n  
=\> 65535

But, I am still receiving “java.net.ConnectException: Cannot assign requested address”.

Do I now need to distribute my testing?

Aidy

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [September 23, 2014, 8:16am UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/2 "2014-09-23T08:16:30Z")

</div>

How long do your virtual users live?  
How many open connections do you have?  
How are your time wait and ephemeral port range values?

---

<div class="post-metadata">

**Author:** ![Empty\_Account1](https://avatars.discourse-cdn.com/v4/letter/e/5f8ce5/32.png) [@Empty\_Account1](https://community.gatling.io/u/Empty_Account1)\
**Post date:** [September 23, 2014, 9:34am UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/3 "2014-09-23T09:34:29Z")

</div>

Hi Stephane,

I followed all the Linux tuning suggestions here: [http://gatling.io/docs/2.0.0-RC3/general/operations.html](http://gatling.io/docs/2.0.0-RC3/general/operations.html) - which got rid of the problem!

Many Thanks

Aidy

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [September 23, 2014, 9:43am UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/4 "2014-09-23T09:43:45Z")

</div>

Great.  
I thought you had already followed them, and was a bit puzzled 🙂

---

<div class="post-metadata">

**Author:** ![JESSICA\_VIDAL](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@JESSICA\_VIDAL](https://community.gatling.io/u/JESSICA_VIDAL)\
**Post date:** [October 10, 2015, 1:03am UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/5 "2015-10-10T01:03:56Z")

</div>

Hi

I got the same error.

Also I followed the instructions from [http://gatling.io/docs/2.0.0-RC2/general/operations.html#os-tuning](http://gatling.io/docs/2.0.0-RC2/general/operations.html#os-tuning)

> These are my configuration:  
> **ulimit -n**  
> 65535  
> **nano /proc/sys/net/ipv4/tcp\_fin\_timeout**  
> 30  
> **nano /proc/sys/net/ipv4/ip\_local\_port\_range**  
> 32768 65535  
> Also I changed
> 
> > **/etc/pam.d/sshd** , I added session required pam\_limits.so  
> > **/etc/ssh/sshd\_config** , I changed UseLogin yes

I am running this test on **10 machines**. This should throw: **500k RPM during 5 min → 2500000 request.**

setUp(

test1.inject(constantUsersPerSec(833) during (500 seconds))

).protocols(httpConf)

What am I doing wrong? When I tried to reach 1 million is ok, but with more than 2 million gatling or the machines go down.

Can someone help me?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Emanuel\_Hategan](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@Emanuel\_Hategan](https://community.gatling.io/u/Emanuel_Hategan)\
**Post date:** [December 18, 2015, 2:28pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/6 "2015-12-18T14:28:27Z")

</div>

I’m having the same issue on ubuntu 14.04.

Just checked the OS tuning section:

$ ulimit -a  
…  
open files (-n) 65536

$ cat /proc/sys/fs/nr\_open  
1048576

$ cat /proc/sys/fs/file-max  
1621050

session required pam\_limits.so is set in all 3 files

$ cat /proc/sys/net/ipv4/tcp\_fin\_timeout  
60

Can you please advise?

Thank you,  
Emanuel

---

<div class="post-metadata">

**Author:** ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)\
**Post date:** [December 18, 2015, 2:51pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/7 "2015-12-18T14:51:10Z")

</div>

On Linux run

ss -s

and look at your TCP count to see if it is around your file descriptor limit.

Otherwise, the message may be from your web server (I think)!

---

<div class="post-metadata">

**Author:** ![Emanuel\_Hategan](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@Emanuel\_Hategan](https://community.gatling.io/u/Emanuel_Hategan)\
**Post date:** [December 18, 2015, 3:31pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/8 "2015-12-18T15:31:19Z")

</div>

Thank you for the quick reply.

$ ss -s  
Total: 1087 (kernel 0)  
TCP: 64775 (estab 233, closed 64510, orphaned 0, synrecv 0, timewait 64509/0), ports 0

It seems to break when it gets around 65535, however, I’ve now set all limits 100 times that

$ ulimit -n  
6553600

$ cat /proc/sys/fs/file-max  
6553600

$ cat /proc/sys/fs/nr\_open  
6553600

Since available ports for testing are between 1025 and 65535, it’s probably because of that.

I’m currently having constantUsersPerSec(1000) that just make one request.

I’m trying to make gatling recycle connections with below settings but no success so far.

```auto
allowPoolingConnections = true # Allow pooling HTTP connections (keep-alive header automatically added)
allowPoolingSslConnections = true # Allow pooling HTTPS connections (keep-alive header automatically added)
maxConnectionsPerHost = 1000 # Max number of connections per host (-1 means no limit)
maxConnections = 1000   

```

Can you spot anything wrong?

Thanks

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [December 18, 2015, 3:36pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/9 "2015-12-18T15:36:02Z")

</div>

Are you the one asking on SOF too? [http://stackoverflow.com/questions/34355828/why-is-gatling-pausing-to-send-requests/34356777](http://stackoverflow.com/questions/34355828/why-is-gatling-pausing-to-send-requests/34356777)

ephemeral ports starvation

---

<div class="post-metadata">

**Author:** ![Emanuel\_Hategan](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@Emanuel\_Hategan](https://community.gatling.io/u/Emanuel_Hategan)\
**Post date:** [December 18, 2015, 3:54pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/10 "2015-12-18T15:54:39Z")

</div>

No, I’m not…

---

<div class="post-metadata">

**Author:** ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)\
**Post date:** [December 18, 2015, 4:29pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/11 "2015-12-18T16:29:39Z")

</div>

Try .shareConnections at the protocol level.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [December 18, 2015, 4:35pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/12 "2015-12-18T16:35:10Z")

</div>

But then your connection profile will be different. Chose the one that matches your needs/live system behavior.

You can also increase your ephemeral port range and reduce your tcp time\_wait.

If you have control over your network, you can also create aliases for your NI and bind from different local addresses.

---

<div class="post-metadata">

**Author:** ![aidylewis](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@aidylewis](https://community.gatling.io/u/aidylewis)\
**Post date:** [December 18, 2015, 5:14pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/13 "2015-12-18T17:14:43Z")

</div>

Yes, you must ask yourself whether a thousand users per second will hit one URL and close the connection. Other load test tools share connections which is unrealistic for browser based tests.

I found this site useful for Linux tuning: [http://www.nateware.com/linux-network-tuning-for-2013.html#.VnQ7hXOnzbt](http://www.nateware.com/linux-network-tuning-for-2013.html#.VnQ7hXOnzbt)

And you can also run off multiple machines and cat the logs.

---

<div class="post-metadata">

**Author:** ![Emanuel\_Hategan](https://avatars.discourse-cdn.com/v4/letter/e/6bbea6/32.png) [@Emanuel\_Hategan](https://community.gatling.io/u/Emanuel_Hategan)\
**Post date:** [December 22, 2015, 3:05pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/14 "2015-12-22T15:05:46Z")

</div>

Thanks, that helped. Although, in the end I’ve ended up refactoring my tests so that a user would make multiple requests.

---

<div class="post-metadata">

**Author:** ![Abhinav\_Vaid](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Abhinav\_Vaid](https://community.gatling.io/u/Abhinav_Vaid)\
**Post date:** [June 1, 2020, 4:25pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/15 "2020-06-01T16:25:28Z")

</div>

Sharing connections did the trick for me!

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [June 1, 2020, 4:36pm UTC](https://community.gatling.io/t/java-net-connectexception-cannot-assign-requested-address/1450/16 "2020-06-01T16:36:49Z")

</div>

shareConnections = simulating server to server traffic

If that’s your use case, fine.

But if your use case is simulating web traffic, no, it didn’t “make the trick”.  
You actually broke your test and made it meaningless.  
You have to properly lift your OS limits as described in this thread and in our documentation, and if it’s not enough, resort to distributed tests eg with Gatling Enterprise.
