Timeouts

Three properties limit time: server.connection-timeout (the network is silent), server.request-timeout (the application is slow), and spring.mvc.async.request-timeout (an SseEmitter stays open).

Why

A server that waits forever can be held up by anyone:

Each property covers one of these cases. They do not replace each other.

Property Limits Default Past it
server.connection-timeout silence while a request body is read; idle keep-alive connections 60s 408, the connection closes; an idle connection closes
server.request-timeout the time the filters and the handler take to start the answer no limit 503; the request's RequestDeadline has passed
spring.mvc.async.request-timeout the life of an SseEmitter without its own timeout no limit onTimeout callbacks, then the emitter completes

Example

# lib/resources/application.yml
server:
  connection-timeout: 30s
  request-timeout: 10s
spring:
  mvc:
    async:
      request-timeout: 30m
server.connection-timeout=30s
server.request-timeout=10s
spring.mvc.async.request-timeout=30m

A handler that reads the deadline between its steps:

import 'package:spring_boot_starter_web/spring_boot_starter_web.dart';

@RestController()
@RequestMapping('/api/reports')
class ReportController {
  ReportController(this.sales, this.stock);
  final SalesClient sales;   // a Feign client: it stops at the request's deadline
  final StockService stock;

  @GetMapping('/daily')
  Future<Report> daily() async {
    final totals = await sales.totals();
    RequestDeadline.current?.check(); // nobody waits any more: stop here
    final levels = await stock.levels();
    return Report(totals, levels);
  }
}

server.connection-timeout

server.request-timeout

Member What
RequestDeadline.current the deadline of the code that runs now, or null
budget the length it was given
remaining the time left; never negative
isExpired whether the time has passed
check() throws a RequestDeadlineExceededException when the time has passed
RequestDeadline.run(budget, body) runs body under a deadline of its own; inside another one, the earlier end wins

What it does not do

spring.mvc.async.request-timeout

@GetMapping('/api/orders/updates')
SseEmitter updates() {
  final emitter = SseEmitter(); // ends after spring.mvc.async.request-timeout
  emitter.onTimeout(() => emitter.send('bye'));
  orders.watch(emitter);
  return emitter;
}

See Server-sent events.

How they work together

At shutdown, spring.lifecycle.timeout-per-shutdown-phase limits how long running requests may still take. See Shutdown.

In Spring (Java)

server.tomcat.connection-timeout=30s
spring.mvc.async.request-timeout=30m

Differences that matter:

See also