最近开发组同事使用Azure的Function App访问公司内部的Oracle数据库时,偶尔会遇到“ORA-12537: Network Session: End of file”这个错误。关于ORA-12537的详细信息如下:
[oracle@DB-Server ~]$ oerr ora 12537
12537, 00000, "TNS:connection closed"
// *Cause: "End of file" condition has been reached; partner has disconnected.
// *Action: None needed; this is an information message.
按照官方文档,引起ORA-12537的错误原因很多,如下所示:
ORA-12537 is an informational message and means that the connection has been closed. This error message can happen due to any of the following reasons:
- There are too many connections being open by the application.
- There are configuration issues in the sqlnet.ora, protocol.ora and listener.ora files.
- Database is shut down (maybe for nightly backup), but connection to database was kept by client.
- A timeout occurred on the client connection.
- A firewall closed idle connections.
- There is a path name that is too long for the Oracle TNS client on Windows. See Note:263489.1
一一分析、排除后,怀疑我设定的一个定期清理超过90分钟空闲会话的作业导致了这个问题,具体参考“ORACLE定期清理INACTIVE会话”,测试了一下,我们通过V$SESSION找到对应的会话,然后使用下面SQL终止会话。
SQL> ALTER SYSTEM DISCONNECT SESSION 'xxx,xxx' IMMEDIATE;
Azure的Function App测试验证发现报“ORA-12537: Network Session: End of file” 。注意:ALTER SYSTEM KILL SESSION 'xxx,xxx' IMMEDIATE;也是同样的错误。
但是如果你使用SQL*Plus等工具(使用SQL*Net连接数据库),测试发现报ORA-03113:通信通道的文件结尾“,而不是ORA-12537这个错误,如下所示:
查了一下官方文档关于Azure的Function(Function App)连接数据库的相关知识,因为连接池缘故,应用程序关闭会话后,连接池对应的数据库会话一直处于INACTIVE状态,而当达到条件时(空闲时间超过90分钟),就被作业清理掉,而此时如果Azure的Function应用再次访问数据库时,由于连接池的相关会话被清理掉了,从而报错。