Skip to content

Commit

Permalink
jetty: out of memory error while uploading large files, add/set max f…
Browse files Browse the repository at this point in the history
…ile threshold jooby-project#399
  • Loading branch information
jknack committed Jun 9, 2016
1 parent 8f24479 commit dcf289a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ public class JettyHandler extends AbstractHandler {
private MultipartConfigElement multiPartConfig;

public JettyHandler(final HttpHandler dispatcher,
final WebSocketServerFactory webSocketServerFactory, final String tmpdir) {
final WebSocketServerFactory webSocketServerFactory, final String tmpdir,
final int fileSizeThreshold) {
this.dispatcher = dispatcher;
this.webSocketServerFactory = webSocketServerFactory;
this.tmpdir = tmpdir;
this.multiPartConfig = new MultipartConfigElement(tmpdir);
this.multiPartConfig = new MultipartConfigElement(tmpdir, -1L, -1L, fileSizeThreshold);
this.addManaged(webSocketServerFactory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ private Server server(final HttpHandler handler, final Config config,
});

server.setHandler(new JettyHandler(handler, webSocketServerFactory, config
.getString("application.tmpdir")));
.getString("application.tmpdir"),
config.getBytes("jetty.http.FileSizeThreshold").intValue()));

return server;
}
Expand Down
2 changes: 2 additions & 0 deletions jooby-jetty/src/main/resources/org/jooby/spi/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jetty {

OutputBufferSize = ${server.http.ResponseBufferSize}

FileSizeThreshold = 16k

SendServerVersion = false

SendXPoweredBy = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void handleShouldSetMultipartConfig() throws Exception {
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(unit.get(HttpHandler.class), unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -84,7 +84,7 @@ public void handleShouldIgnoreMultipartConfig() throws Exception {
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(unit.get(HttpHandler.class), unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -129,7 +129,7 @@ public void handleWsUpgrade() throws Exception {
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(unit.get(HttpHandler.class), unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -175,7 +175,7 @@ public void handleThrowUnsupportedOperationExceptionWhenWsIsMissing() throws Exc
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(unit.get(HttpHandler.class), unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -217,7 +217,7 @@ public void handleThrowUnsupportedOperationExceptionOnNoWebSocketRequest() throw
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(unit.get(HttpHandler.class), unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -261,7 +261,7 @@ public void handleThrowUnsupportedOperationExceptionOnHankshakeRejection() throw
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(unit.get(HttpHandler.class), unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -295,7 +295,7 @@ public void handleThrowUnsupportedOperationExceptionOnWrongType() throws Excepti
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(unit.get(HttpHandler.class), unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -332,7 +332,7 @@ public void handleShouldReThrowServletException() throws Exception {
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(dispatcher, unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -366,7 +366,7 @@ public void handleShouldReThrowIOException() throws Exception {
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(dispatcher, unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -400,7 +400,7 @@ public void handleShouldReThrowIllegalArgumentException() throws Exception {
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(dispatcher, unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down Expand Up @@ -434,7 +434,7 @@ public void handleShouldReThrowIllegalStateException() throws Exception {
.expect(wsStopTimeout)
.run(unit -> {
new JettyHandler(dispatcher, unit.get(WebSocketServerFactory.class),
"target")
"target", -1)
.handle("/", unit.get(Request.class),
unit.get(HttpServletRequest.class),
unit.get(HttpServletResponse.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class JettyServerTest {
.put("HeaderCacheSize", "8k")
.put("RequestHeaderSize", "8k")
.put("ResponseHeaderSize", "8k")
.put("FileSizeThreshold", "16k")
.put("SendServerVersion", false)
.put("SendXPoweredBy", false)
.put("SendDateHeader", false)
Expand Down
2 changes: 1 addition & 1 deletion jooby-netty/src/main/resources/org/jooby/spi/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ netty {

MaxHeaderSize = ${server.http.HeaderSize}

MaxChunkSize = 8k
MaxChunkSize = 16k

MaxContentLength = ${server.http.MaxRequestSize}

Expand Down

0 comments on commit dcf289a

Please sign in to comment.