ipc: Avoid using QLocalServer.setSocketOptions.

This causes problems with AddressInUseError being swallowed.

Fixes #997.
This commit is contained in:
Florian Bruhin 2015-10-07 21:52:09 +02:00
parent 2e46efccdc
commit 7db1f65425
2 changed files with 30 additions and 4 deletions

View File

@ -183,7 +183,7 @@ class IPCServer(QObject):
self._server.newConnection.connect(self.handle_connection)
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 we use setSocketOptions on Unix with Qt < 5.4, we get a
# NameError while listening...
@ -213,7 +213,13 @@ class IPCServer(QObject):
raise ListenError(self._server)
if not self._socketopts_ok: # pragma: no cover
# 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)
@pyqtSlot(int)

View File

@ -299,8 +299,6 @@ class TestListen:
ipc_server.listen()
@pytest.mark.posix
@pytest.mark.xfail(reason="Fails since adding setSocketOptions to "
"IPCServer.")
def test_in_use(self, qlocalserver, ipc_server, monkeypatch):
monkeypatch.setattr('qutebrowser.misc.ipc.QLocalServer.removeServer',
lambda self: True)
@ -896,3 +894,25 @@ def test_socket_options_listen_problem(qlocalserver, short_tmpdir):
assert not ok
assert qlocalserver.serverError() == QAbstractSocket.HostNotFoundError
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