Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart resolver exception handling doesn't appear to work #10928

Closed
ZacharyKlein opened this issue Feb 7, 2018 · 7 comments
Closed

Multipart resolver exception handling doesn't appear to work #10928

ZacharyKlein opened this issue Feb 7, 2018 · 7 comments
Assignees
Milestone

Comments

@ZacharyKlein
Copy link
Member

Steps to Reproduce

  1. Set appropriate maxUploadSize and maxRequestSize config values
  2. Create a custom subclass of StandardMultipartResolver and wire in resources.groovy
  3. Attempt to catch exceptions and set a session variable, returning the request

Expected Behaviour

The request should return a response to the browser, with the appropriate session variable set

Actual Behaviour

The browser never receives a response and errors out with "server connection was reset" message.

Environment Information

  • Operating System: macOS
  • Grails Version: 3.3.2
  • JDK Version: 1.8
  • Container Version (If Applicable): N/A

Example Application

@ZacharyKlein
Copy link
Member Author

For context, my sample project is an updated version of @jameskleeh's post here: https://stackoverflow.com/questions/29845943/grails3-file-upload-maxfilesize-limit/32974072#32974072

@ZacharyKlein
Copy link
Member Author

Via @graemerocher, a partial solution is to set the response status to 413 in the controller.

response.status = HttpStatus.PAYLOAD_TOO_LARGE.value()

This works... sometimes. It appears to resolve the issue on Chrome and Safari, on macOS. However, Firefox on macOS exhibits the same issue (blank page, "connection was reset" message).

What's worse, both Chrome and Firefox on Linux (Ubuntu) continue to display the problematic behavior. I'm told the same is true on Windows.

This is entirely specific to the browser/OS - for example, when the test app is deployed to Tomcat on a remote server (ruling out any development environment specifics), a client on macOS/Safari will receive the correct response (form with an error message), and a client on Ubuntu/Chrome will receive the blank page/connection error.

I'm not sure how to debug this further.

@puneetbehl
Copy link
Contributor

@ZacharyKlein @jameskleeh I am not able to replicate this issue on Mac with Chrome, Firefox, and Safari. It seems to be happening in Linux. I do not have a Linux machine. So, I would request you to please assign it to someone with Linux machine.

@puneetbehl
Copy link
Contributor

ok, I am able to replicate the problem on VirtualBox Linux and on MacOS as well when I try to upload a file with size 20M or more.

It seems like it's related to the Tomcat default connector maxSwallowSize. If you try to upload a file whose size exceeded this value (default 2M) then Tomcat will reset the connection.

I found similar old issue #9378 which is marked as won't-fix.

This is how you do it in a Grails/Spring Boot application: http://stackoverflow.com/questions/32250030/setting-a-tomcat-property-using-spring-boot-application-properties

@ppazos
Copy link

ppazos commented Jun 26, 2020

@ZacharyKlein I'm getting an exception before reaching the controller, where do you put that code?

@ppazos
Copy link

ppazos commented Oct 20, 2020

The issue is not about setting the max size, is about how to manager the exception when the max size is reached in a graceful manner so the user is not bothered, since for every max size set a user can upload a bigger file.

The exception happens in Spring, before the Grails controllers are reached, so it doesn't seem possible to catch the exception from Grails and return a friendly error to the user. IMO this is a pretty basic problem, not sure why this wasn't fixed, or at least why a strategy to deal with this wasn't documented in Grails.

Would be nice is some Grails core member can give a proper solution to this issue any app that allows uploading files will face.

@puneetbehl puneetbehl added this to the grails-4.0.6 milestone Oct 29, 2020
@philippreston
Copy link

Hitting this issue as well. Was there any view on how this can even be worked around? Throwing a 500 isn't particularly elegant or user friendly...

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants