A small service assembles previews for a list of attachments. After a recent change, the behavior became unstable: some requests hang noticeably longer than expected, and with a mixed set of files it is sometimes impossible to get a summary even when all data is available locally.
build method must return Future[Vector[Preview]] for all passed Attachments in the original order.kind = "text", the preview is built from the first limit characters of the content field.kind = "image", the preview is built from the string "image:<bytes>", where <bytes> is the sizeBytes value.label = "unsupported" without aborting the entire request.Future is awaited.PreviewService with an ExecutionContext on a single thread.build for a set of several attachments that includes both text and image.Await.result with a small timeout.kind.Example scenario:
import scala.concurrent.*
import scala.concurrent.duration.*
import java.util.concurrent.Executors
@main def reproduce(): Unit =
given ExecutionContext = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(1))
val service = PreviewService()
val items = Vector(
Attachment("a1", "text", "alpha beta", 0),
Attachment("a2", "image", "", 128),
Attachment("a3", "other", "ignored", 5)
)
println(Await.result(service.build(items, 5), 2.seconds))
label = "unsupported", rather than turning the entire result into an error.3.3.121scala or scalacExecutionContext created via ExecutionContext.fromExecutorService(...)content is already in memory, no external I/OUse line comments to explain the problem, its impact, the fix and how to test it.