spring kinesis binder 尝试释放锁时应用程序停止期间出现 DynamoDB 解锁错误

DynamoDB unlock errors during application stop when spring kinesis binder tries to release lock

当应用程序停止时,kinesis binder 尝试解锁 dynamoDB 并抛出解锁失败异常。

我在 之后遇到了类似的问题,并将 spring-integration-aws 版本更新为 v2.3.1.RELEASE。但是在应用程序关闭时仍然看到相同的错误。

    2020-05-26 16:02:20.445  INFO [] 47251 --- [           main] com.vf.uk.dal.Application   : Started Application in 27.697 seconds (JVM running for 28.31)
    2020-05-26 16:02:20.914  INFO [] 47251 --- [esis-consumer-1] a.i.k.KinesisMessageDrivenChannelAdapter : The [ShardConsumer{shardOffset=KinesisShardOffset{iteratorType=LATEST, sequenceNumber='null', timestamp=null, stream='kinesis-test', shard='shardId-000000000000', reset=false}, state=NEW}] has been started.
    2020-05-26 16:02:49.128  INFO [] 47251 --- [extShutdownHook] a.i.k.KinesisMessageDrivenChannelAdapter : stopped KinesisMessageDrivenChannelAdapter{shardOffsets=[KinesisShardOffset{iteratorType=LATEST, sequenceNumber='null', timestamp=null, stream='kinesis-test', shard='shardId-000000000000', reset=false}], consumerGroup='anonymous.17f05415-386f-4eb5-bdf1-be7d9044f170'}
    2020-05-26 16:02:49.129  INFO [] 47251 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
    2020-05-26 16:02:49.129  INFO [] 47251 --- [extShutdownHook] o.s.i.channel.PublishSubscribeChannel    : Channel 'V1-1.errorChannel' has 0 subscriber(s).
    2020-05-26 16:02:49.129  INFO [] 47251 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : stopped bean '_org.springframework.integration.errorLogger'
    2020-05-26 16:02:49.133 ERROR [] 47251 --- [s-shard-locks-1] a.i.k.KinesisMessageDrivenChannelAdapter : Error during unlocking: DynamoDbLock [lockKey=anonymous.17f05415-386f-4eb5-bdf1-be7d9044f170:kinesis-test:shardId-000000000000,lockedAt=2020-05-26@16:02:20.641, lockItem=null]

    org.springframework.dao.DataAccessResourceFailureException: Failed to release lock at anonymous.17f05415-386f-4eb5-bdf1-be7d9044f170:kinesis-test:shardId-000000000000; nested exception is java.util.concurrent.RejectedExecutionException: Task org.springframework.integration.aws.lock.DynamoDbLockRegistry$DynamoDbLock$$Lambda23/0x0000000800dd6840@11fc5cb1 rejected from java.util.concurrent.ThreadPoolExecutor@145d3a23[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
        at org.springframework.integration.aws.lock.DynamoDbLockRegistry$DynamoDbLock.unlock(DynamoDbLockRegistry.java:526) ~[spring-integration-aws-2.3.1.RELEASE.jar:na]
        at org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter$ShardConsumerManager.run(KinesisMessageDrivenChannelAdapter.java:1294) ~[spring-integration-aws-2.3.1.RELEASE.jar:na]
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
        at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
    Caused by: java.util.concurrent.RejectedExecutionException: Task org.springframework.integration.aws.lock.DynamoDbLockRegistry$DynamoDbLock$$Lambda23/0x0000000800dd6840@11fc5cb1 rejected from java.util.concurrent.ThreadPoolExecutor@145d3a23[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
        at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2055) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:825) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1355) ~[na:na]
        at org.springframework.integration.aws.lock.DynamoDbLockRegistry$DynamoDbLock.unlock(DynamoDbLockRegistry.java:519) ~[spring-integration-aws-2.3.1.RELEASE.jar:na]
        ... 6 common frames omitted

    2020-05-26 16:02:49.133  INFO [] 47251 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
    2020-05-26 16:02:49.139  INFO [] 47251 --- [extShutdownHook] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService 'taskScheduler'
    2020-05-26 16:02:49.158  INFO [] 47251 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'

使用的依赖项:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
    </parent>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-binder-kinesis</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-bus</artifactId>
    </dependency>

如果您向我确认您没有创建自己的 DynamoDbLockRegistry bean,那么我会看到需要更正的地方。

然而,这不应该是应用程序生命周期结束时的严重错误:无论如何您已经停止了它,并且由于该错误而解锁的所有锁都将在下次 leaseDuration 到期时释放。

更新

修复在这里:https://github.com/spring-projects/spring-integration-aws/commit/bc4a1c7c5975555fb5237642b8b97d8633f0f6cb