问题现象
应用通过 OBProxy 执行一个较长的 Batch Insert SQL 语句时,OceanBase 驱动报空指针异常 java.lang.NullPointerException,同时应用断连报错 Caused by: com.oceanbase.jdbc.internal.util.exceptions.OceanBaseSqlException: unexpected end of stream, read 0 bytes from 4。 应用日志报错信息: 应用日志中报错如下(关键错误信息):
java.sql.SQLException: Error
Caused by: java.lang.NullPointerException: null
Caused by: com.oceanbase.jdbc.internal.util.exceptions.OceanBaseSqlException: unexpected end of stream, read 0 bytes from 4
Caused by: java.sql.SQLNonTransientConnectionException: unexpected end of stream, read 0 bytes from 4
其中 java.lang.NullPointerException 在 OceanBase 驱动执行 Batch 的流程中抛出,底层原因为 unexpected end of stream, read 0 bytes from 4,表示与 OceanBase 数据库的连接中断或响应异常,最终表现为 SQLNonTransientConnectionException(非瞬态连接异常,通常意味着网络断开、服务端异常或协议层通信失败)。 obproxy.log 中报错信息:
grep "TRANS_FREE_ROUTE_NOT_SUPPORTED" /home/admin/obproxy/log/obproxy.log*
[2025-xx-xx xx:xx:xx.xxxxxx] WARN [PROXY.TXN] handle_error_resp [36984][Y0-xxxxxxxxxx] [lt=28] [dc=0] get err pkt from observer, not forward to client, will be consumed soon, and maybe need retry(send_action="SERVER_SEND_REQUEST", state="RESPONSE_ERROR", error_type="TRANS_FREE_ROUTE_NOT_SUPPORTED_ERROR", resp={is_trans_completed:false, is_resp_completed:true, ending_type:2, is_partition_hit:true, has_new_sys_var:false, has_proxy_idc_name_user_var:false, is_server_db_reset:false, reserved_len:0, connection_id:0, scramble_buf:"", is_resultset_resp:false, server_capabilities_lower_.capability:0, ok_packet_action_type:2, last_ok_pkt_len:75, rewritten_last_ok_pkt_len:0, extra_info:{is_exist_sess_info:false, sess_info_count:0, extra_len:0}, error_pkt:field_count:255, errcode:6279, sqlstate:"HY000", message:"ORA-06279: Query is not supported to be executed on txn temporary node"})
[2025-xx-xx xx:xx:xx.xxxxxx] WARN [PROXY.TXN] build_oceanbase_ob20_user_request [36984][Y0-xxxxxxxxxx] [lt=65] [dc=0] unexpected buffer len check(ret=-4016, req_buf_avail=4094, client_request_len=4856)
[2025-xx-xx xx:xx:xx.xxxxxx] WARN [PROXY.TXN] build_oceanbase_user_request [36984][Y0-xxxxxxxxxx] [lt=45] [dc=0] fail to build oceanbase ob20 user request(ret=-4016, client_request_len=4856, compress_seq=0)
observer.log 中报错信息:
err_:-6279, err_:"OB_TRANS_FREE_ROUTE_NOT_SUPPORTED", retry_type:0, client_ret:-6279), need_retry=false)
observer.log 中可见 ret=-6279(OB_TRANS_FREE_ROUTE_NOT_SUPPORTED)相关的 WDIAG 日志,例如 query failed(ret=-6279 ...) 等,表明 OBServer 对该 SQL 返回了二次路由不支持的报错。
关键诊断信息
触发条件
- 应用通过 OBProxy 执行长度超过 4KB(对应配置项
request_buffer_length的默认值)的 Batch Insert SQL 语句。 - 该 SQL 在事务内路由状态下被 OBServer 判定需要重新路由,且 OBServer 返回二次路由报错:observer.log 中出现错误码
-6279(OB_TRANS_FREE_ROUTE_NOT_SUPPORTED),或 obproxy.log 中出现TRANS_FREE_ROUTE_NOT_SUPPORTED相关报错。 - OBProxy 版本为 V3.x、V4.x。
事前巡检
- 检查业务是否存在长度超过 4KB 的 Batch Insert 等大请求 SQL。
- 检查 OBProxy 的
request_buffer_length配置项取值(默认 4KB),评估大请求对路由重试的影响。
事后诊断
- 在 obproxy.log 中检索关键字
TRANS_FREE_ROUTE_NOT_SUPPORTED,确认是否存在errcode:6279(ORA-06279)以及ret=-4016(req_buf_avail小于client_request_len)等报错。 - 在 observer.log 中检索错误码
-6279、OB_TRANS_FREE_ROUTE_NOT_SUPPORTED,确认 OBServer 是否对该 SQL 返回了二次路由不支持的报错。 - 在应用日志中确认是否存在
java.lang.NullPointerException及unexpected end of stream, read 0 bytes from 4报错。
问题原因
该问题为 OBProxy V3.x、V4.x 版本上的缺陷。OBProxy 不保证第一次 SQL 路由总是路由正确;当 OBServer 判断该 SQL 需要重新路由时(该判断完全由 OBServer 控制,原因多样),由于 OBProxy 对单个请求最多只能缓存 4KB(对应配置项 request_buffer_length)的 SQL,对于超过 4KB 的请求,OBProxy 暂不支持重试。此时若在事务内路由状态下 OBServer 返回二次路由(对应 observer.log 中的错误码 ret=-6279)或 TRANS_FREE_ROUTE_NOT_SUPPORTED 相关报错,OBProxy 只能断开连接,导致应用侧报空指针异常并断连。
问题的风险及影响
应用执行较长的 Batch Insert SQL 时报错并断连,导致该批次数据插入失败;后续请求需要应用重连后重新提交,影响业务数据写入的连续性。
影响租户
影响 OceanBase 数据库中的 SYS 租户和 Oracle 租户以及 MySQL 租户。
影响版本
| 影响版本 | 修复版本 |
|---|---|
| OBProxy V3.x、V4.x | OBProxy V4.3.4.0 |
解决方法
建议将 OBProxy 集群升级或重装至问题已修复的版本:OBProxy V4.3.4.0。
规避方式
- 规避方式一: 关闭分布式事务路由(将
enable_transaction_internal_routing设置为false)。 在 OBProxy 上执行运维调整参数命令:MySQL [oceanbase]> alter proxyconfig set enable_transaction_internal_routing=false;或者直接在 OCP Web 白屏界面上调整:进入 OBProxy 的参数管理界面,将参数
enable_transaction_internal_routing的值修改为false。 - 规避方式二: 调整 OBProxy 的配置项
request_buffer_length和tunnel_request_size_threshold为'8KB'。MySQL [oceanbase]> alter proxyconfig set request_buffer_length='8KB'; MySQL [oceanbase]> alter proxyconfig set tunnel_request_size_threshold='8KB';调整后不存在大于 4KB 请求重试的场景了,因为超过 8KB 的请求会被直接判定为大请求,发送到协调者,走协调者路由。
注意
从 OBProxy V4.3.1.7 版本开始,`request_buffer_length` 的默认值从 4KB 调整为 8KB,也能规避该问题。