Azure App Services至AI Search私网部署报错InvalidOperationException求助
组件
- Azure App Services
- Azure AI Search
问题概述
通过Azure AI Studio部署sample-app-aoai-chatGPT应用,公网环境运行正常,但建立Azure App Services至Azure AI Search的私网连接时,应用失败并提示:
检测到无效的Azure认知搜索配置:获取ACS索引的调用失败。请检查是否使用了正确的索引、实例和API密钥。
私网配置详情
- Azure App Services已集成到虚拟网络的子网中
- Azure AI Search在同一虚拟网络的另一个子网配置了专用终结点
- Azure AI Search已禁用公网访问
已执行的排查步骤
- 通过Kudu和
nslookup确认DNS解析到私网IP地址 - 启用Azure AI Search公网访问后,应用恢复正常
- 向Azure AI Search专用终结点发起REST API调用可返回预期结果
- Azure App Services至Azure AI服务专用终结点的出站访问正常
相关日志
2024-02-05T16:18:53.465043284Z: [ERROR] [2024-02-05 16:18:53 +0000] [79] [ERROR] Error handling request 2024-02-05T16:18:53.465111184Z: [ERROR] Traceback (most recent call last): 2024-02-05T16:18:53.465117884Z: [ERROR] File "/tmp/8dc1e90f6f97d9f/app.py", line 398, in stream_with_data 2024-02-05T16:18:53.465122784Z: [ERROR] response["model"] = lineJson["model"] 2024-02-05T16:18:53.465126884Z: [ERROR] ~~~~~~~~^^^^^^^^^ 2024-02-05T16:18:53.465130584Z: [ERROR] KeyError: 'model' 2024-02-05T16:18:53.465134384Z: [ERROR] 2024-02-05T16:18:53.465152884Z: [ERROR] During handling of the above exception, another exception occurred: 2024-02-05T16:18:53.465157184Z: [ERROR] 2024-02-05T16:18:53.465160484Z: [ERROR] Traceback (most recent call last): 2024-02-05T16:18:53.465164184Z: [ERROR] File "/opt/python/3.11.4/lib/python3.11/site-packages/gunicorn/workers/sync.py", line 184, in handle_request 2024-02-05T16:18:53.465167984Z: [ERROR] for item in respiter: 2024-02-05T16:18:53.465171484Z: [ERROR] File "/tmp/8dc1e90f6f97d9f/antenv/lib/python3.11/site-packages/werkzeug/wsgi.py", line 256, in __next__ 2024-02-05T16:18:53.465175184Z: [ERROR] return self._next() 2024-02-05T16:18:53.465178684Z: [ERROR] ^^^^^^^^^^^^ 2024-02-05T16:18:53.465182184Z: [ERROR] File "/tmp/8dc1e90f6f97d9f/antenv/lib/python3.11/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded 2024-02-05T16:18:53.465185984Z: [ERROR] for item in iterable: 2024-02-05T16:18:53.465189484Z: [ERROR] File "/tmp/8dc1e90f6f97d9f/app.py", line 425, in stream_with_data 2024-02-05T16:18:53.465193184Z: [ERROR] yield format_as_ndjson({"error" + str(e)}) 2024-02-05T16:18:53.465196884Z: [ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-02-05T16:18:53.465200384Z: [ERROR] File "/tmp/8dc1e90f6f97d9f/app.py", line 170, in format_as_ndjson 2024-02-05T16:18:53.465203984Z: [ERROR] return json.dumps(obj, ensure_ascii=False) + "\n" 2024-02-05T16:18:53.465207684Z: [ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-02-05T16:18:53.465211184Z: [ERROR] File "/opt/python/3.11.4/lib/python3.11/json/__init__.py", line 238, in dumps 2024-02-05T16:18:53.465214984Z: [ERROR] **kw).encode(obj) 2024-02-05T16:18:53.465218384Z: [ERROR] ^^^^^^^^^^^ 2024-02-05T16:18:53.465221884Z: [ERROR] File "/opt/python/3.11.4/lib/python3.11/json/encoder.py", line 200, in encode 2024-02-05T16:18:53.465225484Z: [ERROR] chunks = self.iterencode(o, _one_shot=True) 2024-02-05T16:18:53.465229084Z: [ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-02-05T16:18:53.465232484Z: [ERROR] File "/opt/python/3.11.4/lib/python3.11/json/encoder.py", line 258, in iterencode 2024-02-05T16:18:53.465236184Z: [ERROR] return _iterencode(o, 0) 2024-02-05T16:18:53.465239685Z: [ERROR] ^^^^^^^^^^^^^^^^^ 2024-02-05T16:18:53.465243085Z: [ERROR] File "/opt/python/3.11.4/lib/python3.11/json/encoder.py", line 180, in default 2024-02-05T16:18:53.465246785Z: [ERROR] raise TypeError(f'Object of type {o.__class__.__name__} ' 2024-02-05T16:18:53.465250285Z: [ERROR] TypeError: Object of type set is not JSON serializable 2024-02-05T16:18:53.496122015Z: [INFO] fail: Middleware[0] 2024-02-05T16:18:53.496560416Z: [INFO] Failed to forward request to http://169.254.129.3:8000. Encountered a System.IO.IOException exception after 32272.399ms with message: The response ended prematurely.. Check application logs to verify the application is properly handling HTTP traffic. 2024-02-05T16:18:53.542252109Z: [INFO] fail: Microsoft.AspNetCore.Server.Kestrel[13] 2024-02-05T16:18:53.542295609Z: [INFO] Connection id "0HN1554QM4OJH", Request id "0HN1554QM4OJH:00000002": An unhandled exception was thrown by the application. 2024-02-05T16:18:53.545071321Z: [INFO] System.InvalidOperationException: StatusCode cannot be set because the response has already started. 2024-02-05T16:18:53.545093721Z: [INFO] at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ThrowResponseAlreadyStartedException(String value) 2024-02-05T16:18:53.545213221Z: [INFO] at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.Microsoft.AspNetCore.Http.Features.IHttpResponseFeature.set_StatusCode(Int32 value) 2024-02-05T16:18:53.545217821Z: [INFO] at Microsoft.Azure.AppService.Middleware.Forwarding.RequestForwarder.OnRequest(HttpContext context) in /__w/1/s/src/EasyAuth/Middleware.Forwarding/RequestForwarder.cs:line 90 2024-02-05T16:18:53.545238621Z: [INFO] at Microsoft.Azure.AppService.Middleware.NetCore.AppServiceMiddleware.InvokeAsync(HttpContext context) in /__w/1/s/src/EasyAuth/Microsoft.Azure.AppService.Middleware.NetCore/AppServiceMiddleware.cs:line 140 2024-02-05T16:18:53.545834924Z: [INFO] at Microsoft.Azure.AppService.MiddlewareShim.AutoHealing.AutoHealingMiddleware.Invoke(HttpContext context) in /__w/1/s/src/EasyAuth/Middleware.Host/AutoHealing/AutoHealingMiddleware.cs:line 59 2024-02-05T16:18:53.545862024Z: [INFO] at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
诉求
排查私网环境下应用报错的根本原因,寻求解决方案。
内容的提问来源于stack exchange,提问作者HXK8
相关产品推荐
相关产品推荐

