alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.99k stars 8.59k forks source link

druid查询完成后,返回结果前出现空指针错误 #3325

Open zhangkangxier opened 5 years ago

zhangkangxier commented 5 years ago

Cause: java.lang.NullPointerException

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:139)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:76)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy165.customSql(Unknown Source)
at com.huawei.winscloud.udgd.query.api.impl.PrestoQueryApi.queryBySql(PrestoQueryApi.java:150)
at com.huawei.wins.atomms.basickpievaluation.udgdDataAccess.DataSplitPolicy.getSiteCellContainer(DataSplitPolicy.java:15)
at com.huawei.wins.atomms.basickpievaluation.algorithm.WINSBasicKPIEvaluationModule.processLTEPingPongCsv(WINSBasicKPIEvaluationModule.java:115)
at com.huawei.wins.atomms.basickpievaluation.algorithm.WINSBasicKPIEvaluationModule.winsBasicKPIEvaluationModule(WINSBasicKPIEvaluationModule.java:78)
at com.huawei.wins.atomms.basickpievaluation.winsBasicKPIEvaluationController.WINSBasicKPIEvaluationController.algorithmCalculate(WINSBasicKPIEvaluationController.java:58)
at com.huawei.wins.atomms.controller.AtomMsSubtaskDockerController.run(AtomMsSubtaskDockerController.java:215)
at com.huawei.wins.atomms.basickpievaluation.winsBasicKPIEvaluationController.WINSBasicKPIEvaluationController.asyncRunSubTask(WINSBasicKPIEvaluationController.java:46)
at com.huawei.wins.atomms.basickpievaluation.winsBasicKPIEvaluationController.WINSBasicKPIEvaluationController$$FastClassBySpringCGLIB$$77437f8c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
at org.springframework.cloud.sleuth.instrument.async.TraceAsyncAspect.traceBackgroundThread(TraceAsyncAspect.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.springframework.cloud.sleuth.instrument.async.TraceRunnable.run(TraceRunnable.java:67)
at org.springframework.cloud.sleuth.instrument.async.TraceRunnable.run(TraceRunnable.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException at com.alibaba.druid.pool.DruidPooledConnection.closePoolableStatement(DruidPooledConnection.java:194) at com.alibaba.druid.pool.DruidPooledPreparedStatement.close(DruidPooledPreparedStatement.java:201) at org.apache.ibatis.executor.BaseExecutor.closeStatement(BaseExecutor.java:286) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:65) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) 打出来的栈信息显示类DruidPooledConnection在执行closePoolableStatement时出错,查看源码应该是holder为null image 该holder看了下只有在处理异常时调用Connection的disable才会被置null,目前不清楚为什么会出现这个空指针,业务的日志还有以下线索: image 05::38:04提交的查询请求 image 06:20:30才爆出这个错误,这期间程序一直在等待查询结果未做其他逻辑,查询的是presto,该问题是偶现,正常情况下一秒钟内就返回结果了。 想咨询下wenshao,该种现象是否为druid的链接状态管理出现异常,然后druid自己删除了链接,还是有其他可能的逻辑,麻烦给点思路。

zhangkangxier commented 5 years ago

druid版本是1.1.16

dontraceme commented 5 years ago

druid 1.1.16 遇到同样问题

zhangkangxier commented 5 years ago

在本地重现了异常,当返回后,在DruidPooledConnection类中执行closePoolableStatement函数时,如果在最后的分之停留一会,会报出Statement is closed的SQLException,这个异常会导致Druid的Holder为null,在执行finally时,就出现了Null异常,将前面的异常覆盖了

MrXiaoLinZi commented 6 months ago

你好,这个有解决吗?