首页 > 解决方案 > MongoDB 反应式无法发送完整的信号

问题描述

我正在使用spring webflux + mongodb。当返回一个合并多个通量的更复杂的方法时,我遇到了通量永远不会完成的问题(http 客户端被卡住等待)。

在尝试重现时,以下似乎是问题:

someRepository.findAll().subscribe([etc...]); 尽管数据库中有 15228 个实体,但总是准确地发出 3855 个实体。未播放完整信号。当使用 coreSubscriber 时,订阅者将在 gc 运行时被垃圾收集,这意味着基本上没有任何东西仍在排队。

有谁知道这个问题的原因和/或解决方法?

(测试在 spring-boot-starter-data-mongodb-reactive 2.0.0.RELEASE、2.0.3.RELEASE 和 2.0.4.RELEASE 版本中 100% 发生,假设也发生在中间版本中。Mongo版本:4.0.0)

编辑:相关代码:

public interface LocationRepository extends ReactiveMongoRepository<Location, String> {}

locationRepository.findAll().subscribe(result -> log.info("RESULT "+result), error -> log.info("ERROR"+error),() -> log.info("DONE"));

标签: javaspringmongodbspring-webfluxreactive

解决方案


后来证明这是驱动程序中的死锁。这可以通过在配置mongo时使用AsynchronousSocketChannelStreamFactoryFactory来解决


推荐阅读