Skip to content
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

java.net.BindException: Can't assign requested address when fetching metrics from client in dashboard #670

Closed
Force-King opened this issue Apr 12, 2019 · 9 comments
Labels
kind/question Category issues related to questions or problems

Comments

@Force-King
Copy link

Force-King commented Apr 12, 2019

最近公司准备用Sentinel做限流降级,我本地引入搭建好环境,采用注解@SentinelResource的方式,wiki 中提到的jar 包都引用了,控制台显示正常。
使用压测工具进行压测时,控制台报错如下:

2019-04-12 15:44:08.983 ERROR 2152 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher : fetch metric http://172.30.4.87:8720/metric?startTime=1555055040000&endTime=1555055046000&refetch=false error

java.net.BindException: Can't assign requested address
at sun.nio.ch.Net.connect0(Native Method) ~[na:1.8.0_191]
at sun.nio.ch.Net.connect(Net.java:454) ~[na:1.8.0_191]
at sun.nio.ch.Net.connect(Net.java:446) ~[na:1.8.0_191]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648) ~[na:1.8.0_191]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processSessionRequests(DefaultConnectingIOReactor.java:273) [httpcore-nio-4.4.6.jar:4.4.6]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:139) [httpcore-nio-4.4.6.jar:4.4.6]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) [httpcore-nio-4.4.6.jar:4.4.6]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194) [httpasyncclient-4.1.3.jar:4.1.3]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) [httpasyncclient-4.1.3.jar:4.1.3]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]

环境:
mac os
jdk 1.8
使用工具 idea
web 项目使用spring boot

请问是什么原因?
@jasonjoo2010

@sentinel-bot sentinel-bot added the kind/bug Category issues or prs related to bug. label Apr 12, 2019
@sentinel-bot
Copy link
Collaborator

Hi @Force-King, we detect non-English characters in the issue. This comment is an auto translation from @sentinel-bot to help other users to understand this issue.
We encourage you to describe your issue in English which is more friendly to other users.

Pressure test console error Can't assign requested address

Recently, the company is going to use Sentinel to do the flow-reduction downgrade. I introduced the local environment and adopted the @SentinelResource annotation. The jar packages mentioned in the wiki are all referenced, and the console display is normal.
When using a pressure test tool for pressure measurement, the console reports this:

2019-04-12 15:44:08.983 ERROR 2152 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher : fetch metric http://172.30.4.87:8720/metric?startTime=1555055040000&endTime=1555055046000&refetch=false error

java.net.BindException: Can't assign requested address
at sun.nio.ch.Net.connect0(Native Method) ~[na:1.8.0_191]
at sun.nio.ch.Net.connect(Net.java:454) ~[na:1.8.0_191]
at sun.nio.ch.Net.connect(Net.java:446) ~[na:1.8.0_191]
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648) ~[na:1.8.0_191]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processSessionRequests(DefaultConnectingIOReactor.java:273) [httpcore-nio-4.4.6.jar:4.4.6]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:139) [httpcore-nio-4.4.6.jar:4.4.6]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) [httpcore-nio-4.4.6.jar:4.4.6]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194) [httpasyncclient-4.1.3.jar:4.1.3]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) [httpasyncclient-4.1.3.jar:4.1.3]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]

surroundings:
mac os
jdk 1.8
Use tool idea
Web project using spring boot

May I ask what is the reason?
@jasonjoo2010

@sentinel-bot sentinel-bot changed the title 压测控制台报错 Can't assign requested address Pressure test console error Can't assign requested address Apr 12, 2019
@sczyh30 sczyh30 added kind/question Category issues related to questions or problems and removed kind/bug Category issues or prs related to bug. labels Apr 12, 2019
@sczyh30
Copy link
Member

sczyh30 commented Apr 12, 2019

You may need to check whether your network config is correct.

@sczyh30 sczyh30 changed the title Pressure test console error Can't assign requested address java.net.BindException: Can't assign requested address when fetching metrics from client in dashboard Apr 12, 2019
@sentinel-bot sentinel-bot added the kind/bug Category issues or prs related to bug. label Apr 12, 2019
@sczyh30 sczyh30 removed the kind/bug Category issues or prs related to bug. label Apr 12, 2019
@Force-King
Copy link
Author

Force-King commented Apr 12, 2019

@sczyh30 网络没有问题,压测 10个线程 循环 100次没有问题,循环 10000次就会报这个错了。 压测量大了以后报的错,所以应该和网络配置没关系。

@jasonjoo2010
Copy link
Collaborator

检查 TIME_WAIT连接是不是满了

@jasonjoo2010
Copy link
Collaborator

jasonjoo2010 commented Apr 12, 2019

这个错误一般是在connect的时候,需要随机分配本机上一个空闲的端口用于建立tcp连接,而找不到可用的端口时发生。

When you want create a connection with remote address OS will fetch one spare local port on interface first(TCP is a 4-element protocol: src.addr/src.port/dst.addr/dst.port).

In linux you can:

# sysctl -a | grep ipv4.ip_local_port_range
net.ipv4.ip_local_port_range = 1024 30000

That means you OS will pick an unused port in range from 1024 to 30000. If OS can't find one the invocation will fail.

You can try:

  1. Extend the range to 1024 - 65535
  2. If you don't have so much connection concurrently actually you may suffer TIME_WAIT problem.

TIME_WAIT

TCP conns have several state like: TIME_WAIT, CLOSE_WAIT, FIN_WAIT, FIN2_WAIT due to different closing orders. Some periods of them can be adjust through sysctl but TIME_WAIT. So you must avoid to turn connections into TIME_WAIT (close it correctly) or reduce the period from 60 seconds(hard coding in kernel header) to 1 seconds by recompiling the kernel.

@Force-King
Copy link
Author

Force-King commented Apr 15, 2019

@jasonjoo2010 谢谢,我查看了,TIME_WAIT=16304 的时候开始报错。
网上查看文档:Linux动态端口号默认范围是32768-65535,也就是说,作为客户端连接同一个IP和同一个端口号,最多只能建立30000多个连接,而Mac默认只能建立16000个左右的连接。
确实是连接太多,导致没法创建了,可以设置socket 连接配置参数,参考:https://blog.csdn.net/ys5773477/article/details/73614220

@jasonjoo2010
Copy link
Collaborator

@jasonjoo2010 谢谢,我查看了,TIME_WAIT 还没有达到上限,持续增长的过程中就开始报错了,我在研究一下。。

有数个影响因素,backlog, time_wait, port range等

看了下你的报错,是dashboard端的报错,并且极其可能是可用端口用尽,你可以考虑在另外的节点(非压测节点)上来部署运行Dashboard,另外压测节点要注意调整参数和压测方式,看情况应该多半是压测没用连接池导致大量http短连接或是并发连接数过高

@Force-King
Copy link
Author

@jasonjoo2010 谢谢,我查看了,TIME_WAIT 还没有达到上限,持续增长的过程中就开始报错了,我在研究一下。。

有数个影响因素,backlog, time_wait, port range等

看了下你的报错,是dashboard端的报错,并且极其可能是可用端口用尽,你可以考虑在另外的节点(非压测节点)上来部署运行Dashboard,另外压测节点要注意调整参数和压测方式,看情况应该多半是压测没用连接池导致大量http短连接或是并发连接数过高

压测用的是 Jmeter, Threads =10 ,Loop Count =20000

@Force-King
Copy link
Author

@jasonjoo2010 Your answer is right. Thank you very much

CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Category issues related to questions or problems
Projects
None yet
Development

No branches or pull requests

4 participants