Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending SIGINT to Syncplay connected to mpv rasies an exception #322

Open
daniel-123 opened this issue Jun 4, 2020 · 28 comments
Open

Sending SIGINT to Syncplay connected to mpv rasies an exception #322

daniel-123 opened this issue Jun 4, 2020 · 28 comments
Assignees
Labels
enhancement help wanted Anyone willing to help can fix/implement this Linux

Comments

@daniel-123
Copy link
Contributor

daniel-123 commented Jun 4, 2020

It's a low priority, but Syncplay should try to close itself cleanly upon receiving SIGINT. It's more likely to occur with --no-gui, but it's also possible to encounter it in GUI mode by for example using CTRL+C in the terminal it was ran from.

In this situation Syncplay also stays running for about minute until some timeout occurs.

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/syncplay/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py", line 163, in run
    current_data = self.socket.recv(1024)
ConnectionResetError: [Errno 104] Connection reset by peer
@FichteFoll
Copy link
Contributor

Also happens for me when mpv or syncplay itself are closed normally.

@daniel-123
Copy link
Contributor Author

Are you on current master branch?

@FichteFoll
Copy link
Contributor

I was using 9484e10, let me quickly rebuild.

@FichteFoll
Copy link
Contributor

FichteFoll commented Jun 18, 2020

Also reproducible on a1a5d7b (current master).

@daniel-123
Copy link
Contributor Author

Since on my system it occurs only with SIGINT (with older pyside2 5.13 or 5.14), what you are getting might be something different still. Sadly this means it will likely require some more digging into actual cause.

@FichteFoll
Copy link
Contributor

Including full traceback from #321:

~ ▶ syncplay
Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created.
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/syncplay/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py", line 163, in run
    current_data = self.socket.recv(1024)
ConnectionResetError: [Errno 104] Connection reset by peer
Unhandled Error
Traceback (most recent call last):
  File "/usr/lib/syncplay/syncplay/clientManager.py", line 16, in run
    syncplayClient.start(config['host'], config['port'])
  File "/usr/lib/syncplay/syncplay/client.py", line 841, in start
    reactor.run()
  File "/usr/lib/syncplay/syncplay/vendor/qt5reactor.py", line 303, in run
    self._blockApp.exec_()
  File "/usr/lib/syncplay/syncplay/vendor/qt5reactor.py", line 187, in write
    log.callWithLogger(w, _write)
--- <exception caught here> ---
  File "/usr/lib/python3.8/site-packages/twisted/python/log.py", line 103, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/lib/python3.8/site-packages/twisted/python/log.py", line 86, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/lib/python3.8/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/lib/python3.8/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/usr/lib/syncplay/syncplay/vendor/qt5reactor.py", line 182, in _write
    self.reactor._disconnectSelectable(w, why, False)
  File "/usr/lib/python3.8/site-packages/twisted/internet/posixbase.py", line 255, in _disconnectSelectable
    selectable.connectionLost(f)
  File "/usr/lib/python3.8/site-packages/twisted/internet/tcp.py", line 519, in connectionLost
    self._commonConnection.connectionLost(self, reason)
  File "/usr/lib/python3.8/site-packages/twisted/internet/tcp.py", line 327, in connectionLost
    protocol.connectionLost(reason)
  File "/usr/lib/python3.8/site-packages/twisted/protocols/tls.py", line 403, in connectionLost
    ProtocolWrapper.connectionLost(self, reason)
  File "/usr/lib/python3.8/site-packages/twisted/protocols/policies.py", line 125, in connectionLost
    self.wrappedProtocol.connectionLost(reason)
  File "/usr/lib/python3.8/site-packages/twisted/internet/endpoints.py", line 146, in connectionLost
    return self._wrappedProtocol.connectionLost(reason)
  File "/usr/lib/python3.8/site-packages/twisted/application/internet.py", line 438, in connectionLost
    self._lostNotification(reason)
  File "/usr/lib/python3.8/site-packages/twisted/application/internet.py", line 640, in <lambda>
    lambda _: self._clientDisconnected())
  File "/usr/lib/python3.8/site-packages/automat/_methodical.py", line 244, in _clientDisconnected
    value = output(oself, *a, **k)
  File "/usr/lib/python3.8/site-packages/automat/_methodical.py", line 283, in __call__
    return self.method(oself, *args, **kwargs)
  File "/usr/lib/python3.8/site-packages/twisted/application/internet.py", line 766, in _wait
    self._doWait()
  File "/usr/lib/python3.8/site-packages/twisted/application/internet.py", line 777, in _doWait
    delay = self._timeoutForAttempt(self._failedAttempts)
  File "/usr/lib/syncplay/syncplay/client.py", line 818, in retry
    self.ui.showMessage(getMessage("reconnection-attempt-notification"))
  File "/usr/lib/syncplay/syncplay/client.py", line 1581, in showMessage
    self.showOSDMessage(message, duration=constants.OSD_DURATION, OSDType=OSDType, mood=mood)
  File "/usr/lib/syncplay/syncplay/client.py", line 1611, in showOSDMessage
    self._client._player.displayMessage(message, int(duration * 1000), OSDType, mood)
  File "/usr/lib/syncplay/syncplay/players/mpv.py", line 132, in displayMessage
    self._listener.mpvpipe.show_text(messageString, duration, constants.MPLAYER_OSD_LEVEL)
  File "/usr/lib/syncplay/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py", line 584, in wrapper
    return self.command(name, *args)
  File "/usr/lib/syncplay/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py", line 617, in command
    return self.mpv_inter.command(command, *args)
  File "/usr/lib/syncplay/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py", line 316, in command
    self.socket.send({"command":command_list, "request_id": command_id})
  File "/usr/lib/syncplay/syncplay/players/python_mpv_jsonipc/python_mpv_jsonipc.py", line 156, in send
    raise BrokenPipeError("socket is closed")
builtins.BrokenPipeError: socket is closed

QFileSystemWatcher::removePaths: list is empty
QFileSystemWatcher::removePaths: list is empty

Arch Linux, qt 4.15.0, pyside built from git (44cb6278), syncplay from current master

@Et0h
Copy link
Contributor

Et0h commented Jun 21, 2020

@iwalton3 Do you think the best way to resolve this would be to add an exception_callback or error_callback to python-mpv-jsonipc (similar to quit_callback) to allow those exceptions to be handled by Syncplay, or is there a better/simpler or alternative?

@iwalton3
Copy link

Right now quit_callback is supposed to be called when mpv dies for any reason. The ConnectionResetError might be due to mpv terminating uncleanly. I could just catch all exceptions and call quit_callback.

The BrokenPipeError is the current exception that I pass up for any MPV call where the connection stops existing.

@iwalton3
Copy link

This change should cover the issue: iwalton3/python-mpv-jsonipc@40e3437

@albertosottile
Copy link
Member

@Et0h Should we upgrade our vendor copy of python_mpv_jsonipc to include the fix linked here? At the moment, we are embedding 1.1.11.

@daniel-123
Copy link
Contributor Author

I'm not sure at which point it has changed, but the problem doesn't occur anymore.

@FichteFoll
Copy link
Contributor

FichteFoll commented Mar 8, 2021

I still experience the issue from OP with current master and Python 3.9. I don't seem to be able to reproduce the traceback I reported in this ticket earlier, however.

The most annoying part is that syncplay doesn't actually terminate afterwards, which then blocks my terminal until I suspend and/or kill syncplay.

@FichteFoll
Copy link
Contributor

I don't seem to be able to reproduce the traceback I reported in this ticket earlier, however.

False alarm, I just forgot how to reproduce it. I still get the same traceback when I close the player (mpv).

@daniel-123
Copy link
Contributor Author

daniel-123 commented Mar 8, 2021

@FichteFoll I'm not sure on what version you have tested, but using Python 3.9, mpv 0.32 and git HEAD of Syncplay on my own system I still cannot reproduce this issue. Neither by sending the signal to Syncplay nor to the connected player.

@FichteFoll
Copy link
Contributor

FichteFoll commented Mar 9, 2021

~ ¬ mpv --version
mpv 0.33.0-dirty Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
FFmpeg library versions:
   libavutil       56.51.100
   libavcodec      58.91.100
   libavformat     58.45.100
   libswscale      5.7.100
   libavfilter     7.85.100
   libswresample   3.7.100
FFmpeg version: n4.3.2


~ > python --version
Python 3.9.2

~ ∃ pacman -Ss syncplay
aur/syncplay 1.6.7-1
    synchronize watching movies on mplayer2, vlc, mpv, and mpc-hc on many computers
aur/syncplay-git 1.6.7.r24.g520569c-1 [installed]
    synchronize watching movies on mplayer2, vlc, mpv, and mpc-hc on many computers

~ ∇ syncplay
Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created.
^CException in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/syncplay/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py", line 163, in run
    current_data = self.socket.recv(1024)
ConnectionResetError: [Errno 104] Connection reset by peer

(that's a build from 520569c)

daniel-123 added a commit that referenced this issue Mar 9, 2021
Update to version 1.1.13 to hopefully address #322 fully.
daniel-123 added a commit that referenced this issue Mar 9, 2021
Update to version 1.1.13 to hopefully address #322 fully.
daniel-123 added a commit that referenced this issue Mar 9, 2021
Update to version 1.1.13 to hopefully address #322 fully.
@daniel-123
Copy link
Contributor Author

@FichteFoll could you try out whether PR #400 fixes the problem for you? I think that vendor change was what was supposed to fix the issue in first place.

@daniel-123
Copy link
Contributor Author

@FichteFoll PR #400 has been fixed and merged into main branch. Could you test it now?

If it doesn't I'll might try to replicate the problem on Arch, but that would require me to set up a new VM so I'd prefer to avoid that :)

@FichteFoll
Copy link
Contributor

#400 doesn't seem to affect this issue at all. Closing mpv from a key binding or with ctrl-c from the terminal still results in the exception traces above.

@daniel-123
Copy link
Contributor Author

@FichteFoll That seems really weird given that I don't see that issue with the same versions of Python/Syncplay.

Could you specify what distro you are using? Are you using pyside2/twisted from distro packages or from pip and in what versions?

@FichteFoll
Copy link
Contributor

I use everything from the Arch repos, build syncplay (release or master) with aurutils and did a system update before all that. I also tested with --no-gui with the same results, so I think we can rule out pyside2. The installed twisted version is 20.3.0.

@FichteFoll
Copy link
Contributor

I just recorded a video to show what I'm doing exactly, although it's really just ctrl-c for the terminal and q for mpv.

2021-03-20_14-31-14.mp4
~ ▶ mpv --version
mpv 0.33.0-dirty Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on UNKNOWN
FFmpeg library versions:
   libavutil       56.51.100
   libavcodec      58.91.100
   libavformat     58.45.100
   libswscale      5.7.100
   libavfilter     7.85.100
   libswresample   3.7.100
FFmpeg version: n4.3.2


~ ↻ pacman -Ss syncplay
aur/syncplay 1.6.7-1
    synchronize watching movies on mplayer2, vlc, mpv, and mpc-hc on many computers
aur/syncplay-git 1.6.7.r33.g77ce05d-1 [installed]
    synchronize watching movies on mplayer2, vlc, mpv, and mpc-hc on many computers

~ ¬ python --version
Python 3.9.2

@daniel-123
Copy link
Contributor Author

I've whipped up an Arch container and installed the package from AUR - the problem actually appeared just like for you.

The thing is - it doesn't appear if I just run Syncplay directly from src folder of AUR repository or directly from our upstream repository. It also doesn't occur if I install Syncplay with make install.

This pretty conclusively narrows the problem down to the PKGBUILD and that puts it out of our hands since we aren't maintaining the AUR package. You can try asking the maintainer of that package to see what can be done to fix this. Or just use our AppImage/tarball.

Because of all the above I feel like this issue can be closed on our side. If you or somebody else manages to narrow it down to something within Syncplay itself feel free to reopen the issue.

@FichteFoll
Copy link
Contributor

FichteFoll commented Mar 20, 2021

I can reproduce both problems from a cloned git repo with python syncplayClient.py --no-gui (and my system-wide syncplay removed to make sure there aren't any conflicts). I presume that's what you tried as well?

@daniel-123
Copy link
Contributor Author

daniel-123 commented Mar 20, 2021

Yes, I've tried it on completely fresh Arch installation. Only difference was that I ran ./syncplayClient.py --no-gui rather than using python command. Which might have some effect on environment?

I also ran it with default Syncplay configuration save for host, room and player path.

@FichteFoll
Copy link
Contributor

I also tried removing my mpv config to no avail. Where does syncplay store its configuration? The folder in ~/.config only has some of them, but renaming it didn't remove my nickname and room config, for example.

@daniel-123
Copy link
Contributor Author

Standard config of syncplay is ~/.config/syncplay.ini, but it will also use any .syncplay in the folder tree where the video file is. Kinda like how .htaccess files work in Apache.

@FichteFoll
Copy link
Contributor

I found my configuration file at ~/.syncplay. Renaming that and launching syncplay with command line overrides only, I managed to "fix" the long traceback from closing mpv but not from interrupting syncplay.

~/code/syncplay ж python syncplayClient.py -a syncplay.pl:8999 -n test -r nanatest --no-gui --player-path /usr/bin/mpv
[17:19:46] Attempting to connect to syncplay.pl:8999
[17:19:46] Attempting secure connection
[17:19:46] Successfully reached syncplay.pl (151.80.32.178)
[17:19:46] Secure connection established (TLSv1.3)

Hello test,

The Syncplay latest is available from http://syncplay.pl/


[17:19:46] Successfully connected to server
In room 'nanatest':
*<test>* is not playing a file
^CSocket connection died.
Traceback (most recent call last):
  File "/home/fichte/code/syncplay/syncplay/vendor/python_mpv_jsonipc/python_mpv_jsonipc.py", line 168, in run
    current_data = self.socket.recv(1024)
ConnectionResetError: [Errno 104] Connection reset by peer

The following config file should be able to reproduce the long traceback issue. I have never touched this file by hand before this (evident by me not knowing where it even was, heh) and only removed my media directories and trusted domains.

Details
[client_settings]
name = FichteFoll
room = nanatest
playerpath = /usr/bin/mpv
perplayerarguments = {'/usr/bin/mpv': ''}
slowdownthreshold = 1.5
rewindthreshold = 4.0
fastforwardthreshold = 5.0
slowondesync = True
rewindondesync = True
fastforwardondesync = True
dontslowdownwithme = False
forceguiprompt = True
filenameprivacymode = SendRaw
filesizeprivacymode = SendRaw
unpauseaction = IfOthersReady
pauseonleave = False
readyatstart = True
autoplayminusers = -1.0
autoplayinitialstate = None
mediasearchdirectories = []
sharedplaylistenabled = True
loopatendofplaylist = False
loopsinglefiles = False
onlyswitchtotrusteddomains = True
trusteddomains = []
publicservers = ['syncplay.pl:8995', 'syncplay.pl:8996', 'syncplay.pl:8997', 'syncplay.pl:8998', 'syncplay.pl:8999']
roomlist = []
autoplayrequiresamefilenames = True

[gui]
showosd = True
showosdwarnings = False
showslowdownosd = True
showdifferentroomosd = False
showsameroomosd = True
shownoncontrollerosd = False
showdurationnotification = True
chatinputenabled = False
chatinputfontunderline = False
chatinputfontfamily = sans-serif
chatinputrelativefontsize = 24.0
chatinputfontweight = 1.0
chatinputfontcolor = #FFFF00
chatinputposition = Top
chatdirectinput = False
chatoutputfontfamily = sans-serif
chatoutputrelativefontsize = 24.0
chatoutputfontweight = 1.0
chatoutputfontunderline = False
chatoutputmode = Chatroom
chatmaxlines = 7.0
chattopmargin = 25.0
chatleftmargin = 20.0
chatbottommargin = 30.0
chatmoveosd = True
chatosdmargin = 110.0
notificationtimeout = 3.0
alerttimeout = 5.0
chattimeout = 7.0
chatoutputenabled = False
autosavejoinstolist = True

[general]
language =
checkforupdatesautomatically = False
lastcheckedforupdates = 2021-01-9 14:15:00.988

[server_data]
host = syncplay.pl
port = 8999
password = None

@daniel-123
Copy link
Contributor Author

I did some more digging into this. After a fair bit of trying out various environments, settings and conditions I finally came to conclusion that this must be some sort of race condition. I haven't found any consistent way of triggering it, though it seems most common if I run Syncplay with no file specified and send SIGINT to it before loading any files.

My personal PC I'm testing this on is definitely on faster side (NVMe drive and overclocked Ryzen 5 CPU). All in all though, while I'm reopening the issue I think it might be somewhat hard to actually trace the reason for why this problem is occurring. And personally I see it as minor annoyance given that typical usage doesn't really involve SIGINT in first place. If somebody wants to dig into this I can offer some time with testing out the changes.

@daniel-123 daniel-123 reopened this Mar 22, 2021
Et0h added a commit that referenced this issue Aug 2, 2021
* Create pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Update pythonpackage.yml

* Do not show playback speed change notifications in OSD

* Upbuild and remove debug message

* Strip quotation marks from per-player arguments (#226)

* Delete unmaintained changelog.

Removing old and unmaintained changelog file.

* Add more MPC-HC paths (#398)

* Migrate from AppVeyor to GitHub Actions (#399)

* Disable AppVeyor

* Actions: disable other jobs

* Actions: implement windows job

* Use requirements

* Typo in version parser

* Replace type nul for PowerShell

* Change Python version to 3.7

* buildPy2exe: exclude tcl and tkinter

* buildPy2exe: rename zip archive to include extension

* Actions for Windows: build on Python 3.8

* Re-enable build flow for other platforms

* Remove AppVeyor configuration file

* Add manpages courtesy of Bruno Kleinert #387

* Install the manpages.

* Separate debian package artifacts

Make it so that server and full packages are separate artifacts in CI rather than single zip containing both.

* Fix server deb deployment name in CI workflow

* Fix package filename for debs

* Update mpv json ipc vendor code

Update to version 1.1.13 to hopefully address #322 fully.

* Update setup.py for vendor code of mpv jsonipc

* Build AppImage on Ubuntu 18.04

Temporary workaround for AppImage built on Ubuntu 20.04 crashing with segmentation fault. #401

* Update python_mpv_jsonipc to 1.1.13 keeping our changes

* Remove the AppVeyor badge as we stopped using it.

* Improve playlist advancement for VLC and mpv (#334) (#397)

* Advance playlist on end of file in mpv and VLC
* Update duration for streams to fix playlist advancement (#334)

* Add notice for Python in third party collection file (#404)

* Add notice for Python in third party collection file

* Convert third party notices file to plain text

* Adapt codebase to third party notices format change

* Mark as beta 1 (release 97)

* Mark as 1.6.8 final (build 98)

* Update pt_BR translation, fix typo (#422)

* Bundle libgthread-2.0.so.0 into AppImage

* add libxcb manually

* Add missing libxcb-util to build environment

* Enable GitHub Actions on pull requests

* Bundle libxcb1 into AppImage to fix #380

* Send 32-bit/64-bit context when updating

* Upver to 1.6.9 release 99

* Remove references to IRC (#430)

* Add reference to GitHub discussions

* Update issue templates

* Revert "Merge branch 'master' into master"

This reverts commit 173007e, reversing
changes made to 6105da8.

Co-authored-by: Daniel Wróbel <[email protected]>
Co-authored-by: Alberto Sottile <[email protected]>
Co-authored-by: Daniel Wróbel <[email protected]>
Co-authored-by: Atílio Antônio <[email protected]>
Co-authored-by: Teoh Han Hui <[email protected]>
Co-authored-by: Alberto Sottile <[email protected]>
Co-authored-by: Assistant <[email protected]>
@Et0h Et0h added the help wanted Anyone willing to help can fix/implement this label Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted Anyone willing to help can fix/implement this Linux
Projects
None yet
Development

No branches or pull requests

5 participants