Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

General support for problems installing or using Deluge
Post Reply
Henshin
New User
New User
Posts: 9
Joined: Thu Nov 12, 2015 9:41 pm

Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Henshin »

When I try to download torrents from certain servers, i get a "Connection to the other side was lost in a non-clean fashion" error.
I've only noticed this for a specific private tracker (RevTT) so far.
Currently running Deluge 1.3.15.
Here's the log:

Code: Select all

[DEBUG   ] 17:17:00 auth:199 Received a password via the 1.2 auth method
[INFO    ] 17:17:00 auth:327 Login success (ClientIP XX.XX.XX.XX)
[DEBUG   ] 17:17:00 auth:146 Creating session for admin
[DEBUG   ] 17:17:00 json_api:270 json-request: {"method":"core.get_config","params":[],"id":1}
[DEBUG   ] 17:17:00 json_api:270 json-request: {"method":"web.download_torrent_from_url","params":["https://revolutiontt.me/download.php/8aw8mSr139A/Torrent.Name.Here.torrent?passkey=xxxxxxxxx","applied=3417; uuid=xxxxxxx; u
id=xxxxxxxx"],"id":2}
[DEBUG   ] 17:17:00 json_api:684 filename: /tmp/delugeweb-7jo3sc/Torrent.Name.Here.torrent?passkey=xxxxxxxxx
[DEBUG   ] 17:17:00 json_api:688 cookie: applied=3417; uuid=xxxxxxx; uid=xxxxxxx
[ERROR   ] 17:17:02 json_api:678 Error occurred downloading torrent from https://revolutiontt.me/download.php/8aw8mSr139A/Torrent.Name.Here.torrent?passkey=xxxxxxx
[ERROR   ] 17:17:02 json_api:679 Reason: Connection to the other side was lost in a non-clean fashion: Connection lost.
I thought it could be something related to SSL ciphers but the host supports quite few of them so that shouldn't be the issue.
Can't really figure out what could be the problem. Is there anyway of debugging this better?
I tried to simulate the download file code behaviour on a python script:

Code: Select all

from twisted.web import client, http
from twisted.internet import ssl
from twisted.internet._sslverify import ClientTLSOptions
from twisted.internet import reactor

url="https://revolutiontt.me/download.php/8aw8mSr139A/Torrent.Name.Here.torrent?passkey=xxxxxxxxx"
filename="/tmp/Torrent.Name.Here.torrent"
headers = []
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0"
factory=client.HTTPDownloader(url, filename, headers=headers, agent=agent)

host="revolutiontt.me"
port = 443

from twisted.internet import ssl
from twisted.internet._sslverify import ClientTLSOptions
class TLSSNIContextFactory(ssl.ClientContextFactory):
	"""
	A custom context factory to add a server name for TLS connections.
	"""
	def getContext(self, hostname=None, port=None):
		print "Hostname:",hostname,"Port:",port
		ctx = ssl.ClientContextFactory.getContext(self)
		ClientTLSOptions(hostname, ctx)
		return ctx

ctx_factory = TLSSNIContextFactory()

reactor.connectSSL(host,port,factory,ssl.ClientContextFactory())
But it seems to connect just fine:

Code: Select all

>>> reactor.connectSSL(host,port,factory,ssl.ClientContextFactory())
<twisted.internet.tcp.Connector instance at 0x7f5e1d0671b8>
Any suggestions on this issue?
Thanks.
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Cas »

I am not sure, can you try downloading the file with httpdownloader:

Code: Select all

from twisted.internet import reactor
from deluge.httpdownloader import download_file

url='https://'
filename = '/tmp/test.torrent'
def on_file(result):
    print(result)
    reactor.stop()
d = download_file(url, filename)
d.addBoth(on_file)
reactor.run()
I noticed that it will download a webpage from revolutiontt but sometimes raise a failure so perhaps need to tweak how httpdownloader handles this server.

Edit: Actually can you test with Deluge 2.0 code as it might already be fixed there
Henshin
New User
New User
Posts: 9
Joined: Thu Nov 12, 2015 9:41 pm

Re: Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Henshin »

I've ran the code you suggested. I get the same error:

Code: Select all

# python deluge_test.py 
Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 101, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 597, in _doReadOrWrite
    why = selectable.doRead()
  File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 209, in doRead
    return self._dataReceived(data)
  File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 215, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "/usr/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 422, in dataReceived
    self._flushReceiveBIO()
  File "/usr/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 392, in _flushReceiveBIO
    ProtocolWrapper.dataReceived(self, bytes)
  File "/usr/lib/python2.7/dist-packages/twisted/protocols/policies.py", line 120, in dataReceived
    self.wrappedProtocol.dataReceived(data)
  File "/usr/lib/python2.7/dist-packages/twisted/protocols/basic.py", line 571, in dataReceived
    why = self.lineReceived(line)
  File "/usr/lib/python2.7/dist-packages/twisted/web/http.py", line 459, in lineReceived
    self.handleEndHeaders()
  File "/usr/lib/python2.7/dist-packages/twisted/web/client.py", line 144, in handleEndHeaders
    self.factory.gotHeaders(self.headers)
  File "/usr/lib/python2.7/dist-packages/deluge/httpdownloader.py", line 91, in gotHeaders
    new_file_name = str(headers["content-disposition"][0]).split(";")[1].split("=")[1]
exceptions.IndexError: list index out of range

[Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionLost'>: Connection to the other side was lost in a non-clean fashion: Connection lost.
]
Seems like a bug when handling the content disposition header.

I tried upgrading to Deluge 2.0 as you recommended but I'm running into dependencies problems:

Code: Select all

# /usr/bin/deluged -d -l /var/log/deluge/daemon.log -L info
Traceback (most recent call last):
  File "/usr/bin/deluged", line 9, in <module>
    load_entry_point('deluge==2.0.0.dev7257', 'console_scripts', 'deluged')()
  File "/usr/lib/python2.7/dist-packages/deluge/core/daemon_entry.py", line 90, in start_daemon
    from deluge.core.daemon import is_daemon_running
  File "/usr/lib/python2.7/dist-packages/deluge/core/daemon.py", line 17, in <module>
    from twisted.internet import reactor
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/reactor.py", line 38, in <module>
    from twisted.internet import default
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 56, in <module>
    install = _getInstallFunction(platform)
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 44, in _getInstallFunction
    from twisted.internet.epollreactor import install
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/epollreactor.py", line 24, in <module>
    from twisted.internet import posixbase
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 18, in <module>
    from twisted.internet import error, udp, tcp
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 31, in <module>
    from twisted.internet._newtls import (
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_newtls.py", line 21, in <module>
    from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
  File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 63, in <module>
    from twisted.internet._sslverify import _setAcceptableProtocols
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_sslverify.py", line 39, in <module>
    TLSVersion.TLSv1_1: SSL.OP_NO_TLSv1_1,
AttributeError: 'module' object has no attribute 'OP_NO_TLSv1_1'
It seems that there are some incompatibilities between the Twisted version and the Pyopenssl version.
I couldn't figure it out what's the right version for each of them.
Currently running the following packages versions:

Code: Select all

Twisted              18.7.0      
pyOpenSSL            18.0.0      
ndg-httpsclient      0.5.1          
deluge               2.0.0.dev7257   
Any suggestions?
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Cas »

Ok so that issue was fixed in 1.3-stable: https://git.deluge-torrent.org/deluge/c ... d1b06097f1

With regards Deluge 2.0, how did you install it and what version of OpenSSL is installed on the system? python -m OpenSSL.debug
Henshin
New User
New User
Posts: 9
Joined: Thu Nov 12, 2015 9:41 pm

Re: Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Henshin »

Hey Cas,
Thanks for the support. Is there any way to install the latest 1.3 stable from the repos?
I tried to install it manually using

Code: Select all

python setup.py build && sudo python setup.py install
but I get a similar error than version 2.0:

Code: Select all

# deluged -v   
deluged: 1.3.15
libtorrent: 1.1.10.0
# which deluged
/usr/local/bin/deluged
# deluged -d -L debug
[ERROR   ] 12:42:03 main:248 'module' object has no attribute 'OP_NO_TLSv1_1'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/deluge-1.3.15-py2.7.egg/deluge/main.py", line 240, in start_daemon
    from deluge.core.daemon import Daemon
  File "/usr/local/lib/python2.7/dist-packages/deluge-1.3.15-py2.7.egg/deluge/core/daemon.py", line 41, in <module>
    from twisted.internet import reactor
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/reactor.py", line 38, in <module>
    from twisted.internet import default
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 56, in <module>
    install = _getInstallFunction(platform)
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 44, in _getInstallFunction
    from twisted.internet.epollreactor import install
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/epollreactor.py", line 24, in <module>
    from twisted.internet import posixbase
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 18, in <module>
    from twisted.internet import error, udp, tcp
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 31, in <module>
    from twisted.internet._newtls import (
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_newtls.py", line 21, in <module>
    from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
  File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 63, in <module>
    from twisted.internet._sslverify import _setAcceptableProtocols
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_sslverify.py", line 39, in <module>
    TLSVersion.TLSv1_1: SSL.OP_NO_TLSv1_1,
AttributeError: 'module' object has no attribute 'OP_NO_TLSv1_1'
I tried to rollback to the version available on the ubuntu repos but now I get the same error everytime. I think updating the pyopenssl messed up my system.
By the way that python snippet doesn't work on my server.

Code: Select all

# python -m OpenSSL.debug
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/OpenSSL/debug.py", line 25, in <module>
    crypto_openssl_compile=OpenSSL._util.ffi.string(
AttributeError: 'module' object has no attribute '_util'
I could retrieve the version by tweaking the code a bit though:

Code: Select all

Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import OpenSSL
>>> OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_VERSION)
'OpenSSL 1.0.2g  1 Mar 2016'
>>> 

Code: Select all

# openssl version
OpenSSL 1.0.2g  1 Mar 2016
I was quite surprised that the version is from 2016 :shock: but it seems that it is the latest one available on the ubuntu xenial repos:

Code: Select all

# apt update
Get:1 http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu xenial InRelease [247 kB]
Hit:2 http://security.ubuntu.com/ubuntu xenial-security InRelease         
Get:3 http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Hit:4 http://ppa.launchpad.net/deluge-team/ppa/ubuntu xenial InRelease
Hit:5 http://ppa.launchpad.net/deluge-team/ppa/ubuntu trusty InRelease
Get:6 http://ubuntu.mirrors.ovh.net/ftp.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Fetched 463 kB in 2s (203 kB/s)                              
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up-to-date.
# apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  libtorrent-rasterbar8 python-geoip python-mako python-markupsafe python-rencode
Use 'apt autoremove' to remove them.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
# 
Regarding the version 2.0, I've added the development PPA repos to my sources and installed through APT:

Code: Select all

sudo add-apt-repository ppa:deluge-team/develop
Is this the recommended way to do it?
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Cas »

That is a bit of mess with OpenSSL, are you using Debian? There is no issue on Ubuntu afaik. I wonder if you should remove the apt packages for python-openssl and install via pip.

You could test Deluge 2.0 source with a python virtualenv:

Code: Select all

python -m virtualenv venv --system-site-packages
source venv/bin/activate
pip install -r requirements.txt
Henshin
New User
New User
Posts: 9
Joined: Thu Nov 12, 2015 9:41 pm

Re: Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Henshin »

I downgraded my version of Twisted to 16.4.1 using

Code: Select all

pip install Twisted==16.4.1
and the 1.3 stable is now running fine.
Everything is working now :) The bug with the content disposition is fixed and I'm now able to download torrents from RevTT.
Thanks for your support Cas!
BTW is there a way to get the updates from the latest 1.3 stable automatically?
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Deluge Web client "Connection to the other side was lost in a non-clean fashion" error

Post by Cas »

Excellent

No there isn't but I have pretty much stopped applying fixes in 1.3-stable, primarily as my time is going into polishing 2.0 release.
Post Reply