ASGI send/receive protocol violation: nonlocal body may be overwritten by multiple send calls
The inner send closure captures body via nonlocal and appends to it on each http.response.body message. The ASGI spec allows the application to send multiple body messages (e.g., for streaming). If metrics_app sends more than one body message, body += message.get("body", b"") will concatenate them, which is correct. However, the send closure also captures status_code and headers from http.response.start. If the ASGI app sends http.response.start more than once (which is a protocol violation by the app, but possible), the last one wins. More critically, the receive closure always returns an empty body and more_body=False. If metrics_app calls receive() more than once, it will get the same empty message repeatedly, which is fine. The real risk is that the send closure does not handle the http.response.start message being sent after some body messages (out of order), which would cause status_code to be updated after body has already been accumulated, potentially leading to a 200 response with a body but a status code from a later start message. This is unlikely with prometheus_client's make_asgi_app(), but the code is fragile.