Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BasePreparedStatement的初始化策略问题 #233

Closed
citywalki opened this issue Jun 28, 2019 · 6 comments · Fixed by #236
Closed

BasePreparedStatement的初始化策略问题 #233

citywalki opened this issue Jun 28, 2019 · 6 comments · Fixed by #236
Assignees
Labels
bug Something isn't working
Milestone

Comments

@citywalki
Copy link

Describe the bug

java.lang.IllegalStateException: BasePreparedStatement has not been initialized at com.alipay.sofa.tracer.plugins.datasource.BasePreparedStatement.checkState(BasePreparedStatement.java:98)

当使用JdbcTemplate.update(JdbcTemplate.java:927)方法,由于tracer-datasource-plugin中的BasePreparedStatement会在getParameterMetaData执行前做checkState,但BasePreparedStatement的initialized是被延迟到第一次执行 SQL时才会被初始化,所以会导致checkState失败。

Steps to reproduce

调用JdbcTemplate.update(String sql, @nullable PreparedStatementSetter pss)

Environment

  • SOFATracer version: 3.0.5
  • JVM version (e.g. java -version): 1.8
  • OS version (e.g. uname -a): Win10
  • Maven version: gradle
@citywalki
Copy link
Author

bug又没人管吗?

@glmapper
Copy link
Contributor

glmapper commented Jul 3, 2019

bug又没人管吗?

这个问题内部已经评审过了,会放在下个 2.4.1 / 3.0.6 版本中修复

@glmapper glmapper added this to the 2.4.1 milestone Jul 3, 2019
@citywalki
Copy link
Author

bug又没人管吗?

这个问题内部已经评审过了,会放在下个 2.4.1 / 3.0.6 版本中修复

那就好,我只是怕没人理会那就不太棒了

@glmapper glmapper added the bug Something isn't working label Jul 4, 2019
@glmapper glmapper self-assigned this Jul 4, 2019
@taotao365s
Copy link

taotao365s commented Jul 12, 2019

首先,sofa-tracer-datasource-plugin 思路确实不错

这种错误太致命了,直接影响生产环境
这种场景下也会出现 BasePreparedStatement has not been initialized

  • mybatis & tkmapper
  • druid datasource
 @Autowired
    private SqlSessionFactory sqlSessionFactory;

@Override
    @Transactional(rollbackFor = Exception.class)
    public void insertBatch(List list) {

        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
        XXMapper mapper = sqlSession.getMapper(XXMapper.class);

        for (int i = 0; i < list.size(); i++) {
            mapper.insertSelective(list.get(i));
            if (i % Const.DB_BATCH_SIZE == (Const.DB_BATCH_SIZE - 1)) {
                sqlSession.flushStatements();
            }
        }
        sqlSession.flushStatements();
    }

debug了一下
image
目测stmt被缓存起来了,而这里优先使用了delegate.queryTimeout的方法

@taotao365s
Copy link

@iamcyw do you have demo code?

@citywalki
Copy link
Author

@iamcyw do you have demo code?

抱歉没有,我只是阅读jdbctemlate代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants