NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.96k stars 1.7k forks source link

Could not send response to the client ,version:2.3.1 #564

Open higersister opened 5 years ago

higersister commented 5 years ago

java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:112) at java.net.SocketOutputStream.write(SocketOutputStream.java:157) at fi.iki.elonen.NanoHTTPD$Response.sendBody(NanoHTTPD.java:1694) at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectEncoding(NanoHTTPD.java:1667) at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectTransferAndEncoding(NanoHTTPD.java:1657) at fi.iki.elonen.NanoHTTPD$Response.send(NanoHTTPD.java:1624) at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:957) at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192) at java.lang.Thread.run(Thread.java:761)

macedoraf commented 5 years ago

i've the same problem

RowlandOti commented 5 years ago

Are you streaming a file or sending the whole of it at once?

You may need to add support for byte download if you are downloading stuff. Also may be great to check how many threads are allowed in the server.

sunnyamuren commented 5 years ago

I have the same issue

sunnyamuren commented 5 years ago

t E/fi.iki.elonen.NanoHTTPD: Could not send response to the client java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:117) at java.net.SocketOutputStream.write(SocketOutputStream.java:149) at fi.iki.elonen.NanoHTTPD$Response$ChunkedOutputStream.write(NanoHTTPD.java:1442) at fi.iki.elonen.NanoHTTPD$Response$ChunkedOutputStream.write(NanoHTTPD.java:1435) at java.util.zip.GZIPOutputStream.writeHeader(GZIPOutputStream.java:182) at java.util.zip.GZIPOutputStream.(GZIPOutputStream.java:94) at java.util.zip.GZIPOutputStream.(GZIPOutputStream.java:109) at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectEncoding(NanoHTTPD.java:1663) at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectTransferAndEncoding(NanoHTTPD.java:1654) at fi.iki.elonen.NanoHTTPD$Response.send(NanoHTTPD.java:1624) at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:957) at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192) at java.lang.Thread.run(Thread.java:784)

FonzTech commented 5 years ago

This happens to me when loading an audio through JavaFX's WebView.

EDIT: This error does not happen on old version. I tried the 2.1.1 on Maven Repository. It works even with the JavaFX's WebView!

mvock commented 4 years ago

In my case, I got this error after calling com.fasterxml.jackson.databind.ObjectMapper#readTree(session.getInputStream()). Reading the body myself with InputStream.readNBytes(length) where length is the value of the content-length header works.

FonzTech commented 4 years ago

@mvock I think the problem is due to NanoHttpd that closes the socket too early (or it sends a command causing the other side to close the socket, causing a broken pipe) but then it continues to write to it.

timehaswings commented 3 years ago

I have the same issue

FonzTech commented 3 years ago

I have the same issue

Try a previous version, if it's not a problem for you.

pir8radio commented 1 year ago

so try an old version is the fix? :-) I see this just serving up json API requests on a reasonably busy server. maybe the json response is long? not sure the pattern, I run a production and a test, my test only has 6 or so users hitting it every few seconds, the problem server (production) has 180 users all hitting the api call every second or two. I see zero of these errors on the low traffic test server, but constantly on the production server. if that helps.. are there any timeouts or settings I could look into?

Sep 23, 2023 10:31:36 AM fi.iki.elonen.NanoHTTPD$Response send SEVERE: Could not send response to the client java.net.SocketException: Software caused connection abort: socket write error at java.base/java.net.SocketOutputStream.socketWrite0(Native Method) at java.base/java.net.SocketOutputStream.socketWrite(Unknown Source) at java.base/java.net.SocketOutputStream.write(Unknown Source) at fi.iki.elonen.NanoHTTPD$Response$ChunkedOutputStream.finish(NanoHTTPD.java:1448) at fi.iki.elonen.NanoHTTPD$Response.sendBodyWithCorrectTransferAndEncoding(NanoHTTPD.java:1655) at fi.iki.elonen.NanoHTTPD$Response.send(NanoHTTPD.java:1624) at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:957) at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192) at java.base/java.lang.Thread.run(Unknown Source)