Skip to content

Wrong WebRequest in RestControllerAdvice #35651

@w-ronin

Description

@w-ronin

I have probably race condition here (Spring Boot 3.5.6):

@Log4j2
@RestControllerAdvice
public class GlobalExceptionsHandler extends ResponseEntityExceptionHandler {

    public static final String REQUEST_ID = "_requestId";

    @ExceptionHandler({ItemNotFoundException.class, DependentNotFoundException.class})
    protected ErrorResponse handleNotFoundException(Exception ex, WebRequest request) {
        try (final Instance ignored = put(REQUEST_ID, request.getParameter(REQUEST_ID))) {
            LOG.info(ex);
            return ErrorResponse.builder(ex, HttpStatus.NOT_FOUND, ex.getMessage()).build();
        }
    }
}

I see wrong REQUEST_ID in logs from parallel running request.
2025-10-16T15:11:00,635 [read-330] INFO d.d.e.e.c.GlobalExceptionsHandler : ff5c2ad3-53ee-4748-ae64-e961462f092e : ........DependentNotFoundException: The requested dependent resource was not found.

In RestController the service runs under new WebAsyncTask<>(...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions