Skip to content

Sending more data after response is finished causes "thread panicked" #707

@nggit

Description

@nggit

Hello,

The following case is tested on granian 2.5.5 (cpython 3.12.11, linux):

async def app(scope, receive, send):
    assert scope['type'] == 'http'

    await send({
        'type': 'http.response.start',
        'status': 200,
        'headers': [
            (b'content-type', b'text/plain'),
        ]
    })

    # body
    await send({
        'type': 'http.response.body',
        'body': b'Hello, ',
        'more_body': False
    })
    await send({
        'type': 'http.response.body',
        'body': b'World!'
    })

The response is correct, further messages are ignored... but it will also shut down.

[INFO] Starting granian (main PID: 21519)
[INFO] Listening at: http://127.0.0.1:9000
[INFO] Spawning worker-1 with PID: 21520
[WARNING] ASGI Lifespan errored, continuing without Lifespan support (to avoid Lifespan completely use "asginl" interface)
[INFO] Started worker-1
[INFO] Started worker-1 runtime-1

thread '<unnamed>' panicked at src/asgi/io.rs:222:93:

called Option::unwrap() on a None value
stack backtrace:
0: 0x7f8e94565282 -
1: 0x7f8e9449f213 -
2: 0x7f8e94564ddf -
3: 0x7f8e945650e3 -
4: 0x7f8e94564a8d -
5: 0x7f8e945904d5 -
6: 0x7f8e94590469 -
7: 0x7f8e9459111c -
8: 0x7f8e93e57f3f -
9: 0x7f8e93e5807b -
10: 0x7f8e93e58228 -
11: 0x7f8e94278f21 -
12: 0x7f8e94d7bca0 -
13: 0x7f8e94d7ac38 - PyObject_Vectorcall
14: 0x7f8e94c8b4d9 -
15: 0x7f8e94d9a07c -
16: 0x7f8e93ad4798 -
17: 0x7f8e93ad54ea -
18: 0x7f8e94d8d015 - _PyObject_Call
19: 0x7f8e92c34ce7 -
20: 0x7f8e92c3d66c -
21: 0x7f8e92c4a0bf -
22: 0x7f8e94d854d0 -
23: 0x7f8e94d7ac38 - PyObject_Vectorcall
24: 0x7f8e94c8b4d9 -
25: 0x7f8e94da6fee - PyObject_VectorcallMethod
26: 0x7f8e93e6dfe3 -
27: 0x7f8e94297b50 -
28: 0x7f8e942e60b8 -
29: 0x7f8e94d7bca0 -
30: 0x7f8e94d7ac38 - PyObject_Vectorcall
31: 0x7f8e94c8b4d9 -
32: 0x7f8e94d69adf - _PyObject_FastCallDictTstate
33: 0x7f8e94d898be - _PyObject_Call_Prepend
34: 0x7f8e94d896a0 -
35: 0x7f8e94d678cb -
36: 0x7f8e94d676ab - _PyObject_MakeTpCall
37: 0x7f8e94c8b4d9 -
38: 0x7f8e94d9df2d -
39: 0x7f8e94d8d14a -
40: 0x7f8e94c8bb17 -
41: 0x7f8e94d9df2d -
42: 0x7f8e94d8d14a -
43: 0x7f8e94c8bb17 -
44: 0x7f8e94d69b70 - _PyObject_FastCallDictTstate
45: 0x7f8e94d898be - _PyObject_Call_Prepend
46: 0x7f8e94e31350 -
47: 0x7f8e94d67744 - _PyObject_MakeTpCall
48: 0x7f8e94c8b4d9 -
49: 0x7f8e94de82d3 - PyEval_EvalCode
50: 0x7f8e94e24557 -
51: 0x7f8e94e1f78c -
52: 0x7f8e94e1c2a3 -
53: 0x7f8e94e1bda2 - _PyRun_SimpleFileObject
54: 0x7f8e94e1bae4 - _PyRun_AnyFileObject
55: 0x7f8e94e188a3 - Py_RunMain
56: 0x7f8e94dd1d57 - Py_BytesMain
57: 0x7f8e9529370a -
[ERROR] Unexpected exit from worker-1
[INFO] Shutting down granian

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    asgiIssue related to ASGI protocolbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions