搜索错误关键字“Cannot assign requested address”,"返回" JSON 内容,返回的引号是因为其实并不是远程接口返回的,而是 IdentityModel 返回的,毕竟直译后从字面意思理解“无法分配请求的地址”,也可以理解为不能正确发起请求,所以就是在发起请求的过程中产生的错误。

在和运维一起排查后得知被调用服务出现很多 close wait,导致连接数不能及时释放,连接数耗尽,所以就不能再建立新请求了。知道了原因接下来就好办了。顺藤摸瓜,找到发起请求的地方,将能 Close Dispose 的都处理了。

错误返回的完整内容如下:

{"AccessToken": null,"IdentityToken": null,"TokenType": null,"RefreshToken": null,"ErrorDescription": null,"ExpiresIn": 0,"Raw": null,"Json": null,"Exception": {"Message": "Cannot assign requested address","Data": {},"InnerException": {"ClassName": "System.Net.Sockets.SocketException","Message": "Cannot assign requested address","Data": null,"InnerException": null,"HelpURL": null,"StackTraceString": "at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)","RemoteStackTraceString": null,"RemoteStackIndex": 0,"ExceptionMethod": null,"HResult": -2147467259,"Source": "System.Private.CoreLib","WatsonBuckets": null,"NativeErrorCode": 99},"StackTrace": "at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)\n   at System.Threading.Tasks.ValueTask`1.get_Result()\n   at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)\n   at System.Threading.Tasks.ValueTask`1.get_Result()\n   at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)\n   at System.Threading.Tasks.ValueTask`1.get_Result()\n   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)\n   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\n   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)\n   at IdentityModel.Client.TokenClient.RequestAsync(IDictionary`2 form, CancellationToken cancellationToken)","HelpLink": null,"Source": "System.Net.Http","HResult": -2147467259},"IsError": true,"ErrorType": 3,"HttpStatusCode": 0,"HttpErrorReason": null,"Error": "Cannot assign requested address"
}

修改前源代码

/// <summary>
/// 统一获取 SpiderBIM token的通用方法
/// </summary>
/// <param name="config">配置信息</param>
/// <returns></returns>
public static TokenResponse GetAuthorizeAsync(SpiderBIMConfigOptions config)
{var tokenClient = new TokenClient(config.TokenUrl, config.ClientId, config.ClientSecret);var tokenResponse = tokenClient.RequestResourceOwnerPasswordAsync(config.Username, config.Password, config.Scope).GetAwaiter().GetResult();if (tokenResponse.IsError){Console.WriteLine($"DEBUG {DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} - ---------------------------- 获取 SPDToken 失败 ----------------------------{tokenResponse.ToJsonString()}");return null;}return tokenResponse;
}

修改后的代码

/// <summary>
/// 统一获取 SpiderBIM token的通用方法
/// </summary>
/// <param name="config">配置信息</param>
/// <returns></returns>
public static TokenResponse GetAuthorizeAsync(SpiderBIMConfigOptions config)
{using (var tokenClient = new TokenClient(config.TokenUrl, config.ClientId, config.ClientSecret)){var tokenResponse = tokenClient.RequestResourceOwnerPasswordAsync(config.Username, config.Password, config.Scope).GetAwaiter().GetResult();if (tokenResponse.IsError){Console.WriteLine($"DEBUG {DateTime.Now:yyyy-MM-dd HH:mm:ss,fff} - ---------------------------- 获取 SPDToken 失败 ----------------------------{tokenResponse.ToJsonString()}");return null;}return tokenResponse;}
}

修改后的代码加上了 using 是的 tokenClient 在使用后及时被释放,避免被调用服务出现太多的 close wait。从而导致连接数被占用完。

所以就是因为没有注意到 tokenClient 是可以被 Dispose 的类,并且因为业务关系发起了频繁的请求,所以才导致问题的产生。

无法分配请求的地址(Cannot assign requested address)的解决方案相关推荐

  1. java.net.NoRouteToHostException: Cannot assign requested address

    启动脚本 jmeter.sh -n -t test.jmx -l result.jtl 参数说明 - h 帮助 -> 打印出有用的信息并退出 - n 非GUI模式 -> 在GUI模式下进行 ...

  2. 记录一次etcd报错: listen tcp xxx.xxx.xxx.xxx:2380:bind: cannot assign requested address

    记录一次etcd报错 背景 问题定位 问题排查 解决方案 小结 背景 今天打算在腾讯云环境上安装k8s(采用ansible脚本自动化部署安装),当安装完etcd之后,发现启动报错. 机器:腾讯云服务器 ...

  3. I.MX6 ifconfig: SIOCSIFHWADDR: Cannot assign requested address

    /*************************************************************************** I.MX6 ifconfig: SIOCSIF ...

  4. 阿里云,百度云等云服务器中搭建gitblit-1.8.0时,报java.net.BindException: Cannot assign requested address: bind

    搭建gitblit-1.8.0服务器时,启动gitblit.cmd时,报如下错误: 2019-06-16 14:07:36 [WARN ] FAILED ServerConnector@1ba2af2 ...

  5. Cannot assign requested address解决办法

    问题原因: TCP/IP的状态图: "Cannot assign requested address."是由于linux分配的客户端连接端口用尽,无法建立socket连接所致,虽然 ...

  6. fastdfs errno: 99, error info: Cannot assign requested address

    其他解决方案:https://blog.csdn.net/xiangliangyu/article/details/18447861 [2014-01-18 12:42:18] ERROR - fil ...

  7. The client socket has failed to connect to X (errno: 99 - Cannot assign requested address).

    在跑DDP模型时遇到了如下问题. [W socket.cpp:558] [c10d] The client socket has failed to connect to [localhost]:12 ...

  8. Linux客户端连接报错:Cannot assign requested address

    前言 在项目中写了一个MQTT的客户端小程序,用于测试MQTTServer的连接数上限,运行了一段时间后报错:Cannot assign requested address 网上查了下"Ca ...

  9. 阿里云配置服务器报:bind: cannot assign requested address

    阿里云服务器写网络程序时必须使用阿里云服务器的内网ip,不是他的公网ip,访问时是公网ip.具体可见下面这篇文章,十分感谢!!!!使得我写的小程序可以在服务器上运行,和前端小伙伴项目可以进行下去. 参 ...

最新文章

  1. Android 属性动画(Property Animation) ObjectAnimator的介绍
  2. python圣诞树代码成品图片动态_Python 圣诞树和樱花树源码
  3. C语言经典例67-数组最大值与最小值与数组元素交换
  4. eclipse安装快速打开项目所在位置的插件
  5. Android开发之Java和Calendar日期上一年,上一个月,前一天,前一周的方法
  6. C++调用matlab dll
  7. bodhi linux 安装 ubuntu软件,Bodhi Linux 5.1.0 发布,基于Ubuntu的轻量级发行版
  8. RabbitMQ入门:路由(Routing)
  9. 趋势:“无人化”的未来,这些事情你需要知道!
  10. 明天支付宝就开始提现收费了!这几招可以让你受用
  11. 人工智能时代的危机_AI信任危机:如何前进
  12. UnboundLocalError: local variable 'XXX' referenced before assignment
  13. SparkSQL——各区域热门商品TOP3
  14. 《安富莱嵌入式周报》第245期:2021.12.20--2021.12.26
  15. EEG 信号频带功率计算
  16. Linux系统下如何复制粘贴
  17. 5. 数据库题(以个人熟悉数据库为准、按要求写出sql) (1) 计算每个人的总成绩并排名(要求显示字段:学号,姓名,总成绩) (2) 计算每个人单科的最高成绩(要求显示字段: 学号,姓名,课程,最
  18. QA的职责和角色定位
  19. LDO与三端稳压器详解
  20. 计算机语言与智能家居的关系,来谈谈“智能家居”与“家庭自动化”的区别

热门文章

  1. CMDB(运维自动化)
  2. 2021年焊工(技师)考试资料及焊工(技师)试题及解析
  3. java技术网面整理
  4. 【Unity3D】血条(HP)
  5. 英文书《用unreal来学习c++》_股市高人经常用“开盘八法”来预判股票一天的走势,可以学习学习...
  6. 【论文】龙王山小青椒 - 论文写作指导
  7. WIN7下安装Oracle 10g 的详细过程以及有关问题的解决(转)
  8. MAC地址查询 Linux/Unix操作系统mac地址怎么查
  9. Multisim应用举例2.8
  10. Notion 团队人才画像