Opened 5 years ago

Last modified 7 weeks 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:


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/", line 128, in connectionLost
    return self._wrappedProtocol.connectionLost(reason)
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/", line 911, in dispatcher
    return func(*args, **kwargs)
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/", line 1564, in _connectionLost_TRANSMITTING
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/", line 812, in stopWriting
--- <exception caught here> ---
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/", line 192, in _callAppFunction
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/web/", line 1016, in stopProducing
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/internet/", line 464, in stop
  File "/home/immerrr/.conda/envs/twisted14/lib/python2.7/site-packages/twisted/internet/", 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.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) (2.2 KB) - added by immerrr 5 years ago.
script to display the described error
tentative-test-for-7427-and-7457.patch (2.3 KB) - added by immerrr 4 years ago.
add two test cases for #7427 and #7457

Download all attachments as: .zip

Change History (4)

comment:1 Changed 5 years ago by DefaultCC Plugin

Cc: jknight added

Changed 5 years ago by immerrr

Attachment: added

script to display the described error

Changed 4 years ago by immerrr

add two test cases for #7427 and #7457

comment:2 Changed 7 weeks ago by Richard van der Hoff

This seems to be a duplicate of ?

Last edited 7 weeks ago by Richard van der Hoff (previous) (diff)
Note: See TracTickets for help on using tickets.