]> git.ipfire.org Git - thirdparty/knot-resolver.git/commit
daemon: handle IO error when processing wire buffer
authorTomas Krizek <tomas.krizek@nic.cz>
Thu, 3 Sep 2020 11:10:04 +0000 (13:10 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Wed, 23 Sep 2020 10:08:18 +0000 (12:08 +0200)
commit8ad2db6e4af6b2537be3e4e2ec7d12a5943c614a
treedb45436c885d0c7243371d57c791cfb365817ccc
parentadccb464e6e6ccdad1998b25ee292155d2462048
daemon: handle IO error when processing wire buffer

This fixes the following assert:
daemon/worker.c:1157: qr_task_finalize: Assertion `!session_flags(source_session)->closing' failed.

Scenario which leads to the above error:
1. We're using a stateful protocol.
2. Enough data arrive in a single tcp_recv() call to put at least
   two queries into the session's wire buffer.
3. session_wirebuf_process() calls worker_submit() which calls
   qr_task_step().
4. In the qr_task_step() the query state changes to KR_STATE_DONE,
   then qr_task_finalize() is called.
5. qr_task_send() is called, but it fails. This is where
   qr_task_finalize() closes the session, but used to return no error.
6. When the next query is processed in session_wirebuf_process(),
   steps 3 and 4 are followed and qr_task_finalize() is called.
7. Since the session is already closed, the assert is triggered.

Debugging this was a lot of fun... All hail the rr debugger!
daemon/session.c
daemon/worker.c