{"action":"created","issue":{"url":"https://api.github.com/repos/rlovtangen/grails-wkhtmltopdf/issues/4","labels_url":"https://api.github.com/repos/rlovtangen/grails-wkhtmltopdf/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/rlovtangen/grails-wkhtmltopdf/issues/4/comments","events_url":"https://api.github.com/repos/rlovtangen/grails-wkhtmltopdf/issues/4/events","html_url":"https://github.com/rlovtangen/grails-wkhtmltopdf/issues/4","id":96254388,"number":4,"title":"\"getOutputStream() has already been called\" when rendering pdf","user":{"login":"rlovtangen","id":233839,"avatar_url":"https://avatars.githubusercontent.com/u/233839?v=3","gravatar_id":"","url":"https://api.github.com/users/rlovtangen","html_url":"https://github.com/rlovtangen","followers_url":"https://api.github.com/users/rlovtangen/followers","following_url":"https://api.github.com/users/rlovtangen/following{/other_user}","gists_url":"https://api.github.com/users/rlovtangen/gists{/gist_id}","starred_url":"https://api.github.com/users/rlovtangen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlovtangen/subscriptions","organizations_url":"https://api.github.com/users/rlovtangen/orgs","repos_url":"https://api.github.com/users/rlovtangen/repos","events_url":"https://api.github.com/users/rlovtangen/events{/privacy}","received_events_url":"https://api.github.com/users/rlovtangen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-21T08:03:12Z","updated_at":"2015-07-21T10:11:55Z","closed_at":"2015-07-21T10:11:55Z","body":"Sometimes I get an exception with message \"getOutputStream() has already been called\".\r\n\r\n````\r\nERROR org.grails.web.errors.GrailsExceptionResolver - IOException occurred when processing request: [GET] /foo/index.pdf\r\nBroken pipe. Stacktrace follows:\r\njava.lang.reflect.InvocationTargetException: null\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_31]\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_31]\r\n\tat java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]\r\nCaused by: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe\r\n\tat wkhtmltopdfapp.FooController.index(FooController.groovy:7) ~[main/:na]\r\n\t... 3 common frames omitted\r\nCaused by: java.io.IOException: Broken pipe\r\n\t... 4 common frames omitted\r\nERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[grailsDispatcherServlet] - Servlet.service() for servlet [grailsDispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause\r\njava.lang.IllegalStateException: getOutputStream() has already been called for this response\r\n\tat java.io.FilterWriter.flush(FilterWriter.java:100) ~[na:1.8.0_31]\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_31]\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_31]\r\n\tat java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]\r\nERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[grailsDispatcherServlet] - Servlet.service() for servlet grailsDispatcherServlet threw exception\r\njava.lang.IllegalStateException: getOutputStream() has already been called for this response\r\n\tat org.apache.catalina.connector.Response.getWriter(Response.java:578) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:212) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView.render(ErrorMvcAutoConfiguration.java:196) ~[spring-boot-autoconfigure-1.2.5.RELEASE.jar:1.2.5.RELEASE]\r\n\tat org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:190) ~[cache-3.0.1.jar:na]\r\n\tat grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) ~[cache-3.0.1.jar:na]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:73) ~[grails-web-mvc-3.0.3.jar:3.0.3]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:523) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:433) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:305) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:399) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31]\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_31]\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.23.jar:8.0.23]\r\n\tat java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]\r\n````\r\n\r\nController:\r\n````\r\n    def index() { \r\n        render( filename:\"File hepp.pdf\",\r\n                view:\"/foo/index\",\r\n                model:[someInstance:\"bar\"],\r\n                marginLeft:20,\r\n                marginTop:35,\r\n                marginBottom:20,\r\n                marginRight:20,\r\n                headerSpacing:10\r\n        )\r\n\r\n    }\r\n````\r\nview:\r\n````\r\n<html>\r\n<head>\r\n</head>\r\n<body>\r\n<h1>Hello</h1>\r\n</body>\r\n</html>\r\n````\r\nDoes not happen every time.\r\nCurrent render method from trait WkhtmltopdfRenderer is:\r\n````\r\n    void render(Map params) {\r\n        if (params.contentType?.toLowerCase() == 'application/pdf' || response.format == \"pdf\") {\r\n            def filename = params.remove(\"filename\")\r\n\r\n            def data = applicationContext.wkhtmltoxService.makePdf(params)\r\n\r\n            response.setHeader(\"Content-disposition\", \"attachment; filename=${filename}\")\r\n            response.contentType = \"application/pdf\"\r\n            response.outputStream.write(data)\r\n            response.characterEncoding = 'UTF-8'\r\n            response.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate') //HTTP/1.1\r\n            response.setHeader('Pragma', 'no-cache') // HTTP/1.0\r\n            response.outputStream.flush()\r\n\r\n        } else {\r\n            // Defer to original render method\r\n            super.render(params)\r\n        }\r\n    }\r\n````\r\nThe pdf rendering part is more or less untouched from the original Grails 2 version of the plugin.\r\n"},"comment":{"url":"https://api.github.com/repos/rlovtangen/grails-wkhtmltopdf/issues/comments/123250005","html_url":"https://github.com/rlovtangen/grails-wkhtmltopdf/issues/4#issuecomment-123250005","issue_url":"https://api.github.com/repos/rlovtangen/grails-wkhtmltopdf/issues/4","id":123250005,"user":{"login":"rlovtangen","id":233839,"avatar_url":"https://avatars.githubusercontent.com/u/233839?v=3","gravatar_id":"","url":"https://api.github.com/users/rlovtangen","html_url":"https://github.com/rlovtangen","followers_url":"https://api.github.com/users/rlovtangen/followers","following_url":"https://api.github.com/users/rlovtangen/following{/other_user}","gists_url":"https://api.github.com/users/rlovtangen/gists{/gist_id}","starred_url":"https://api.github.com/users/rlovtangen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlovtangen/subscriptions","organizations_url":"https://api.github.com/users/rlovtangen/orgs","repos_url":"https://api.github.com/users/rlovtangen/repos","events_url":"https://api.github.com/users/rlovtangen/events{/privacy}","received_events_url":"https://api.github.com/users/rlovtangen/received_events","type":"User","site_admin":false},"created_at":"2015-07-21T10:11:55Z","updated_at":"2015-07-21T10:11:55Z","body":"Turns out Chrome is prefetching URLs as I type. Started out with http://localhost:8080/foo/index in Chrome, then as I type \".pdf\" a request is sent to http://localhost:8080/foo/index.pdf for each letter I type. If I press `Enter` to quick after pressing the last character (`f`) I get the last request before the previous one has finished and this causes the error. If I pause for a second before hitting `Enter` then I don't get the error.\r\nIn `chrome://settings/` under advanced settings, there is a setting called \"Prefetch resources to load pages more quickly\". This is what causes these requests before I hit Enter."}}