# Buggy code
def do_server_playback(self, flow):
    """
    This method should be called by child classes in the handle_request
    handler. Returns True if playback has taken place, None if not.
    """
    if self.server_playback:
        rflow = self.server_playback.next_flow(flow)
        if not rflow:
            return None
        response = HTTPResponse.from_state(rflow.response.get_state())
        response.is_replay = True
        if self.refresh_server_playback:
            response.refresh()
        flow.reply(response)
        if self.server_playback.count() == 0:
            self.stop_server_playback()
        return True
    return None


# Traceback (ValueError)
Error: Connection killed
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/venv/bin/mitmdump", line 9, in <module>
load_entry_point('mitmproxy', 'console_scripts', 'mitmdump')()
File "/home/christofferqa/mitmproxy/mitmproxy/main.py", line 102, in mitmdump
master.run()
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 354, in run
return flow.FlowMaster.run(self)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 128, in run
self.tick(self.masterq, 0.1)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 828, in tick
return super(FlowMaster, self).tick(q, timeout)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 113, in tick
self.handle(*msg)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 135, in handle
m(obj)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 337, in handle_response
self._process_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 321, in _process_flow
self.state.delete_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 584, in delete_flow
self.flows._remove(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 496, in _remove
self._list.remove(f)
ValueError: list.remove(x): x not in list
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 121, in handle
root_layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
----------------------------------------
Error in processing of request from 127.0.0.1:41084
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/netlib/tcp.py", line 854, in connection_thread
self.handle_client_connection(connection, client_address)
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 64, in handle_client_connection
h.handle()
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 152, in handle
self.channel.tell("clientdisconnect", root_layer)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 68, in tell
m.reply = DummyReply()
AttributeError: 'NoneType' object has no attribute 'reply'

# Fixed code
def do_server_playback(self, flow):
    """
    This method should be called by child classes in the handle_request
    handler. Returns True if playback has taken place, None if not.
    """
    if self.server_playback:
        rflow = self.server_playback.next_flow(flow)
        if not rflow:
            return None
        response = HTTPResponse.from_state(rflow.response.get_state())
        response.is_replay = True
        if self.refresh_server_playback:
            response.refresh()
        flow.response = response
        if self.server_playback.count() == 0:
            self.stop_server_playback()
        return True
    return None