Opened 4 years ago

Last modified 4 years ago

#7457 defect new

FileBodyProducer may be stopped twice if the conn is closed remotely

Reported by: immerrr Owned by:
Priority: normal Milestone:
Component: web Keywords:
Cc: jknight Branch:
Author:

Description

Here's what I see in the traceback:

Unexpected exception from twisted.web.client.FileBodyProducer.stopProducing
Traceback (most recent call last):
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/internet/endpoints.py", line 128, in connectionLost
    return self._wrappedProtocol.connectionLost(reason)
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/_newclient.py", line 911, in dispatcher
    return func(*args, **kwargs)
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/_newclient.py", line 1564, in _connectionLost_TRANSMITTING
    self._currentRequest.stopWriting()
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/_newclient.py", line 812, in stopWriting
    _callAppFunction(self.bodyProducer.stopProducing)
--- <exception caught here> ---
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/_newclient.py", line 192, in _callAppFunction
    function()
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/client.py", line 1016, in stopProducing
    self._task.stop()
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/internet/task.py", line 464, in stop
    self._checkFinish()
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/internet/task.py", line 474, in _checkFinish
    raise self._completionState

The sequence of actions that lead to this stacktrace are defined in twisted.internet.tcp.Connection.connectionLost:

t.i.tcp.connectionLost
|
+-> t.abstract.FileDescriptor.connectionLost(...)
|   -> FileBodyProducer.stopProducing()
|   -> t.i.task.CooperativeTask.stop()
|
`-> t.w._newclient.HTTP11ClientProtocol.connectionLost(...)
    -> t.w._newclient.makeStatefulDispatcher.dispatcher(...)
    -> t.w._newclient.HTTP11ClientProtocol._connectionLost_TRANSMITTING(...)
    -> t.w._newclient.Request.stopWriting()
    -> FileBodyProducer.stopProducing()
    -> t.i.task.CooperativeTask.stop()
    -> t.i.task._checkFinish()
    -- raise self._completionState

It appears that a simple guard in FileBodyProducer.stopProducing is enough to prevent this error. I'm sending a minimal test case to reproduce the behaviour.

Attachments (2)

twisted_reproduce2.py (2.2 KB) - added by immerrr 4 years ago.
script to display the described error
tentative-test-for-7427-and-7457.patch (2.3 KB) - added by immerrr 3 years ago.
add two test cases for #7427 and #7457

Download all attachments as: .zip

Change History (3)

comment:1 Changed 4 years ago by DefaultCC Plugin

Cc: jknight added

Changed 4 years ago by immerrr

Attachment: twisted_reproduce2.py added

script to display the described error

Changed 3 years ago by immerrr

add two test cases for #7427 and #7457

Note: See TracTickets for help on using tickets.