Skip to content

firestore.BulkWriter: RejectedExecutionException thrown when close() method is called. #2220

@colin-chan

Description

@colin-chan

Hello,

The following problem was first reported to our support contract with Google, and they then suggested to open an issue here.

After updating our Firestore SDK library, com.google.cloud:firestore, to version 3.32.0 on 2025-08-04, our production log file started to consistently display the following 2 error level messages. They would always appear when our application needed to write out to several thousand documents using BulkWriter. Our application code were not changed, only the library was updated. The errors have never appeared on any prior sdk version before the 3.32.0 update

com.google.common.util.concurrent.AbstractFuture executeListener
SEVERE: RuntimeException while executing runnable com.google.cloud.firestore.BulkWriter$$Lambda/0x00000070014aed80@65519bfb with executor java.util.concurrent.Executors$DelegatedScheduledExecutorService@63906533

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@69fabe3[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@f433a68[Wrapped task = com.google.cloud.firestore.BulkWriter$$Lambda/0x00000070014aed80@65519bfb]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@7ce7e83c[Shutting down, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 123]
    at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2081)
    at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:841)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:340)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:562)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:705)
    at java.base/java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:754)
    at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1307)
    at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:1070)
    at com.google.common.util.concurrent.AbstractFuture.setFuture(AbstractFuture.java:863)
    at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.setResult(AbstractTransformFuture.java:242)
    at com.google.common.util.concurrent.AbstractTransformFuture$AsyncTransformFuture.setResult(AbstractTransformFuture.java:218)
    at com.google.common.util.concurrent.AbstractTransformFuture.run(AbstractTransformFuture.java:176)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1583)

In reviewing the release notes for 3.32.0 there was this change made

Implement BulkWriter shutdown logic (#2202) (7301774)

Suspecting the change to BulkWriter.close() may be the cause I wrote this simple demonstration in Kotlin that managed to reproduce the same error logs.

The bulkWriter uses all the default options. The 10 second wait may not be necessary as the exceptions where still thrown before then right after bulkWriter.close().

    fun main() {

        val firestore = getFirestore()

        val bulkWriter = firestore.bulkWriter()

        List(1000) { mapOf("id" to "$it") }.forEach { model ->
            val docRef = firestore.collection(COLLECTION_NAME).document(model["id"] as String)
            bulkWriter.set(docRef, model)
        }

        bulkWriter.close()

        Thread.sleep(10000)
        firestore.close()
        println("Finished")
    }

I've tested this on:

macOS 15.6
openJDK 21.0.6
IntelliJ IDEA 2025.1.3 (Ultimate Edition)

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/java-firestore API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions