Comments (6)
So, client connection closes mid-response are a bit of an odd case in the Plug lifecycle.
On the one hand, the various Plug.Conn.send_*
calls generally return error tuples to indicate that there was an error sending whatever they were trying to send, and so the app should probably do something about it (most likely, give up on the response).
On the other hand, the only thing a Plug is supposed to do is to handle a request, so it has no business living any longer than necessary to do that one job. Once we've seen a client close, there's no possible way to bring the response to completion, so raising an error is arguably the correct thing to do.
Partly to try and square this circle, I've recently done some pretty substantial refactors of both the HTTP/1 and HTTP/2 stacks (the HTTP/2 is merged into main but unreleased, the HTTP/1 work is in #297). Once merged, Bandit's behaviour in this case will be to raise a relevant exception, and terminate the response handling for you. You'll still have these errors in your logs though (because, hey, we're just telling you your clients are closing early). Why your clients are doing this is up to you; by the time this happens there's no way for the server to mitigate the issue. Note that Cowboy, in its typical fashion, is silent about these error and just doesn't log anything. Presumably they're still happening there, just silently.
(Aside: I'd be interested in seeing the rest of that second 'received unexpected message' line!)
from bandit.
Thank you for this detailed reply.
To answer your curiosity, this is the full log line. The :data part is probably the binary chunk passed to the client.
2024-02-13T13:34:56.481017973Z stdout F 13:34:56.445 request_id=d57eab7afcac53b9d9dd6fd309b66214 [error] Bandit.HTTP1.Handler #PID<0.250641.0> received unexpected message in handle_info/2: {#Port<0.186415>, {:data,
<<48, 48, 48, 53, 49, 51, 81, 32, 66, 79, 82, 32, 32, 48, 48, 69, 72, 78, 80, 70, 7, 223, 0, 23, 7, 8, 46, 0, 11, 15, 20, 102, 0, 100, 0, 1, 0, 32, 0, 2, 0, 0, 0, 0, 0, 64, ...>>}}
In my code, when this case happens, I just close the relevant things but let the Plug.Conn live it's life until the end of the request.
case Plug.Conn.chunk(conn, datachunk) do
{:ok, conn} ->
IO.binwrite(device, datachunk)
stream_dataselect_output(conn, p, device)
true
{:error, e} ->
Logger.error("Error sending chunk to client: #{inspect(e)}")
# TODO Should we close connection here ?
# Like this ?
# Plug.Conn.halt(conn)
false
end
from bandit.
That {:data, ....}
tuple - is that something you're sending to your own processes (or maybe that a library is?)
from bandit.
from bandit.
from bandit.
Great! I was worried that that was something internal to Bandit; given that it's coming from something external of yours, then that messages is expected.
from bandit.
Related Issues (20)
- Plug.BadRequestError and Plug.TimeoutError HOT 16
- Dealing with "request line read error" HOT 11
- Detailed Benchmark Comparison (not just Cowboy, but Go/Java/etc) HOT 4
- Password for key in SSL HOT 4
- Plug.Conn.chunk does not send the chunk to client HOT 3
- Unknown adapter Bandit.Adapter after update to Bandit 1.4.0 HOT 3
- Content-Length header gets overridden HOT 3
- High Memory usage for DelegatingHandler.init/1 HOT 24
- Missing measurements in telemetry events HOT 6
- Plug.Conn is not closed when user closes the browser's tab (SSE) HOT 14
- High CPU usage HOT 2
- Compression configuration options HOT 1
- Clearing process dictionary breaks on some keys HOT 2
- Bandit + Phoenix LiveView on Safari iOS Fails to Reconnect HOT 6
- More examples in documentation HOT 1
- Otel question HOT 2
- Reproducible: Server hangs on every other request HOT 6
- Exceptions get logged from Firefox client, but not from cURL HOT 9
- Lots of `(Bandit.HTTPError) closed` errors HOT 5
- Consider sticking to semantic versioning
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bandit.