codahale/dropwizard — pull request #385 by laurachart (2013-09-03 20:00:44+00:00)
Title: Added new exception mapper for when a client disconnecting in the middle...

... of parsing the input stream causes a jetty Early EOF/500. This is just a normal disconnect so it shouldn't return a 500

Issue:
In a range of drop wizard services we are seeing, in the log files, exceptions relating to EarlyEOFException (org.eclipse.jetty.io.EofException: early EOF).

Reproduce:
This exception has been reproduced consistently in a sample drop wizard service as follows:
1)Start the service in debug which is a simple message storing service and break before exception is thrown in JacksonMessageBodyProvider readfrom method
2)In the terminal - use curl to do a put with a large json file:
curl -vvv -H "Content-Type: application/json" -X PUT --data-binary "@json_load.json" localhost:8080/v1/messages/12
3) Ctrl C in the terminal to try and simulate disconnecting the client.
4) Continue program running from the breakpoint in Step 1) and the exception occurs as follows:

ERROR [2013-09-03 19:45:53,783] com.yammer.dropwizard.jersey.LoggingExceptionMapper: Error handling a request: 507b398b2dc34feb
! org.eclipse.jetty.io.EofException: early EOF
! at org.eclipse.jetty.server.HttpInput.read(HttpInput.java:65) ~[jetty-server-8.1.10.v20130312.jar:8.1.10.v20130312]
! at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.loadMore(UTF8StreamJsonParser.java:174) ~[jackson-core-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.core.base.ParserBase.loadMoreGuaranteed(ParserBase.java:431) ~[jackson-core-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString2(UTF8StreamJsonParser.java:2111) ~[jackson-core-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString(UTF8StreamJsonParser.java:2092) ~[jackson-core-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.getValueAsString(UTF8StreamJsonParser.java:291) ~[jackson-core-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:24) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:375) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:107) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:308) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.ObjectReader._bind(ObjectReader.java:1169) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:625) ~[jackson-databind-2.1.4.jar:2.1.4]
! at com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:448) ~[jackson-jaxrs-json-provider-2.1.4.jar:2.1.4]
! at com.yammer.dropwizard.jersey.JacksonMessageBodyProvider.readFrom(JacksonMessageBodyProvider.java:61) ~[dropwizard-core-0.6.2.jar:na]
………

Summary:
So it appears that LogExceptionMapper returns a server error 500 in this case.

Request:
We would like to request the addition of an Exception mapper to handle the timeout/disconnect whilst in the middle of JSON processing to return a NO_CONTENT response rather than a 500.

I have added the registration of the EarlyEOFExceptionMapper to the Environment class : e.g
jerseyConfig.getSingletons().add(new EarlyEOFExceptionMapper());
due to the fact that Jersey and Jetty are both referenced within the mapper registration.

@64BitChris