ipc: Avoid using QLocalServer.setSocketOptions.
This causes problems with AddressInUseError being swallowed. Fixes #997.
This commit is contained in:
parent
2e46efccdc
commit
7db1f65425
@ -183,7 +183,7 @@ class IPCServer(QObject):
|
|||||||
self._server.newConnection.connect(self.handle_connection)
|
self._server.newConnection.connect(self.handle_connection)
|
||||||
|
|
||||||
self._socket = None
|
self._socket = None
|
||||||
self._socketopts_ok = os.name == 'nt' or qtutils.version_check('5.4')
|
self._socketopts_ok = os.name == 'nt'
|
||||||
if self._socketopts_ok: # pragma: no cover
|
if self._socketopts_ok: # pragma: no cover
|
||||||
# If we use setSocketOptions on Unix with Qt < 5.4, we get a
|
# If we use setSocketOptions on Unix with Qt < 5.4, we get a
|
||||||
# NameError while listening...
|
# NameError while listening...
|
||||||
@ -213,7 +213,13 @@ class IPCServer(QObject):
|
|||||||
raise ListenError(self._server)
|
raise ListenError(self._server)
|
||||||
if not self._socketopts_ok: # pragma: no cover
|
if not self._socketopts_ok: # pragma: no cover
|
||||||
# If we use setSocketOptions on Unix with Qt < 5.4, we get a
|
# If we use setSocketOptions on Unix with Qt < 5.4, we get a
|
||||||
# NameError while listening...
|
# NameError while listening.
|
||||||
|
# (see b135569d5c6e68c735ea83f42e4baf51f7972281)
|
||||||
|
#
|
||||||
|
# Also, we don't get an AddressInUseError with Qt 5.5:
|
||||||
|
# https://bugreports.qt.io/browse/QTBUG-48635
|
||||||
|
#
|
||||||
|
# This means we only use setSocketOption on Windows...
|
||||||
os.chmod(self._server.fullServerName(), 0o700)
|
os.chmod(self._server.fullServerName(), 0o700)
|
||||||
|
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
|
@ -299,8 +299,6 @@ class TestListen:
|
|||||||
ipc_server.listen()
|
ipc_server.listen()
|
||||||
|
|
||||||
@pytest.mark.posix
|
@pytest.mark.posix
|
||||||
@pytest.mark.xfail(reason="Fails since adding setSocketOptions to "
|
|
||||||
"IPCServer.")
|
|
||||||
def test_in_use(self, qlocalserver, ipc_server, monkeypatch):
|
def test_in_use(self, qlocalserver, ipc_server, monkeypatch):
|
||||||
monkeypatch.setattr('qutebrowser.misc.ipc.QLocalServer.removeServer',
|
monkeypatch.setattr('qutebrowser.misc.ipc.QLocalServer.removeServer',
|
||||||
lambda self: True)
|
lambda self: True)
|
||||||
@ -896,3 +894,25 @@ def test_socket_options_listen_problem(qlocalserver, short_tmpdir):
|
|||||||
assert not ok
|
assert not ok
|
||||||
assert qlocalserver.serverError() == QAbstractSocket.HostNotFoundError
|
assert qlocalserver.serverError() == QAbstractSocket.HostNotFoundError
|
||||||
assert qlocalserver.errorString() == 'QLocalServer::listen: Name error'
|
assert qlocalserver.errorString() == 'QLocalServer::listen: Name error'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.posix
|
||||||
|
def test_socket_options_address_in_use_problem(qlocalserver, short_tmpdir):
|
||||||
|
"""Qt seems to ignore AddressInUseError when using socketOptions.
|
||||||
|
|
||||||
|
With this test we verify this bug still exists. If it fails, we can
|
||||||
|
probably start using setSocketOptions again.
|
||||||
|
"""
|
||||||
|
servername = str(short_tmpdir / 'x')
|
||||||
|
|
||||||
|
s1 = QLocalServer()
|
||||||
|
ok = s1.listen(servername)
|
||||||
|
assert ok
|
||||||
|
|
||||||
|
s2 = QLocalServer()
|
||||||
|
s2.setSocketOptions(QLocalServer.UserAccessOption)
|
||||||
|
ok = s2.listen(servername)
|
||||||
|
print(s2.errorString())
|
||||||
|
# We actually would expect ok == False here - but we want the test to fail
|
||||||
|
# when the Qt bug is fixed.
|
||||||
|
assert ok
|
||||||
|
Loading…
Reference in New Issue
Block a user