Skip to content

StandardServletMultipartResolver.resolveMultipart invoked multiple times for same request #13841

Closed

Description

@codeconsole

The following should be analyzed because off hand it seems inefficient. Multipart requests are resolved multiple times for handling url mappings which appears to be real inefficient.

https://github.com/grails/grails-core/blob/6f9d173e0af20a852971aad78a42cc42bba7fd80/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/UrlMappingsHandlerMapping.groovy#L157

https://github.com/grails/grails-core/blob/6f9d173e0af20a852971aad78a42cc42bba7fd80/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/GrailsControllerUrlMappings.java#L45-L67

https://github.com/grails/grails-core/blob/6f9d173e0af20a852971aad78a42cc42bba7fd80/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/AbstractGrailsControllerUrlMappings.groovy#L185-L203

-> DefaultUrlMappingInfo.tryMultipartParams is invoked for every UrlMappingInfo because of the call to getActionName()

https://github.com/grails/grails-core/blob/6f9d173e0af20a852971aad78a42cc42bba7fd80/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/AbstractUrlMappingInfo.java#L70-L102

https://github.com/grails/grails-core/blob/6f9d173e0af20a852971aad78a42cc42bba7fd80/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingInfo.java#L197-L205

due to checkDispatchAction(webRequest.getCurrentRequest());

https://github.com/grails/grails-core/blob/6f9d173e0af20a852971aad78a42cc42bba7fd80/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingInfo.java#L215-L221

Activity

  1. added this to the grails:7.0.0 milestone on Aug 5, 2025
  2. jamesfredley commented on Oct 2, 2026

    @jamesfredley
    Contributor

    This is fixed on 8.0.x.

    DefaultUrlMappingInfo.getActionName() called checkDispatchAction(), which called tryMultipartParams() and then MultipartResolver.resolveMultipart() while URL mappings were matched, in addition to the dispatcher''s own checkMultipart. That call was removed in 611061e (#15565, 2026-04-08). That commit is in v8.0.0-M1, v8.0.0-M2, v8.0.0-M3, v8.0.0-M4, v8.0.0-M5, v8.0.0-M6, v8.0.0-RC1, and v8.0.0-RC2. The unused tryMultipartParams method, which contained resolver.resolveMultipart(request), was deleted in 32b0d9f (#16149, 2026-08-14). That commit is in v8.0.0-RC1 and v8.0.0-RC2. Both commits are on current origin/8.0.x (d13aa33282).

    On that HEAD, getActionName() only evaluates the action name (DefaultUrlMappingInfo.java lines 193-196). GrailsDispatcherServlet.checkMultipart (GrailsDispatcherServlet.groovy lines 90-118) delegates to Spring once per dispatch and skips error, forward, and include requests. WebUtils.resolveMultipartRequest only finds a request that was already resolved. GrailsDispatcherServletSpec expects multipartResolver.resolveMultipart exactly once for a multipart request and zero times otherwise.

    The old path is still on 7.2.x (DefaultUrlMappingInfo.java lines 206, 241, and 278).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions