question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LogUtil requests response body in dev (debug) mode and fails for every InputStream based response

See original GitHub issue

Using 4.0.0.RC0 and serving just a regular InputStream as a response:

ctx.result(App::class.java.getResourceAsStream("/test.file"))
    .encoding(Charsets.UTF_8)
    .contentType(MimeTypes.getDefaultMimeByExtension(uri))

Results in IOException with config.enableDevLogging() enabled:

18:35:31.983 INFO | An exception occurred while logging debug-info: java.io.IOException: Stream closed
	at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
	at java.io.BufferedInputStream.reset(BufferedInputStream.java:446)
	at io.javalin.http.Context.resultString(Context.kt:332)
	at io.javalin.core.util.LogUtil.resBody(LogUtil.kt:59)
	at io.javalin.core.util.LogUtil.requestDevLogger(LogUtil.kt:37)
	at io.javalin.http.JavalinServlet.service$finishUpResponse(JavalinServlet.kt:76)
	at io.javalin.http.JavalinServlet.service(JavalinServlet.kt:83)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at io.javalin.jetty.JavalinJettyServlet.service(JavalinJettyServlet.kt:59)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at io.javalin.jetty.JettyServer$start$wsAndHttpHandler$1.doHandle(JettyServer.kt:52)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:516)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:386)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)
	at java.lang.Thread.run(Thread.java:748)

It looks like this method tries to read again a closed stream:

https://github.com/tipsy/javalin/blob/7c89245250e2433a8f2b6331ddc194dbc6ebdf47/javalin/src/main/java/io/javalin/core/util/LogUtil.kt#L59

Despite of this exception, server properly serves this result file.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
tipsycommented, Aug 11, 2021

After the regex routing is disabled by default.

1reaction
tipsycommented, Aug 9, 2021

You’ll get

Body is an InputStream which can't be reset, so it can't be logged in case your resultStream can’t be reset now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log requests and responses using Spring resttemplate
Getting below error: aused by: java.lang.IllegalArgumentException: No InputStream specified at org.springframework.util.Assert.
Read more >
How to debug http request & responses with body in a human ...
Currently if we try to log the request & response, the libray logs the request & response bodies in a machine readable way...
Read more >
How to log the request body in a Spring Boot application
When your application sends a response, the data of the response is ... the input stream we see a failure that the request...
Read more >
Log Incoming Requests In Spring - Java Development Journal
In this post, we will explore as of how to Log Incoming Requests In Spring. We will explore different options to accomplish it...
Read more >
Troubleshooting requests - Postman Learning Center
Troubleshooting requests · Sending requests · Debugging with the Console | Postman Level Up · Powerful Debugging with the Postman Console · Using ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found