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

beets bpd crash #3007

Closed
hrehfeld opened this issue Aug 19, 2018 · 4 comments · Fixed by #3215
Closed

beets bpd crash #3007

hrehfeld opened this issue Aug 19, 2018 · 4 comments · Fixed by #3215
Labels
bug bugs that are confirmed and actionable

Comments

@hrehfeld
Copy link

hrehfeld commented Aug 19, 2018

Problem

beets bpd crashes when accessed with mpd client (while fetching albums for artist?).

$ beet -vv bpd
user configuration: /home/hrehfeld/.config/beets/config.yaml
data directory: /home/hrehfeld/.config/beets
plugin paths: 
Sending event: pluginload
library database: /home/hrehfeld/.local/beets.blb
library directory: /home/hrehfeld/music/2017
Sending event: library_opened
Building directory tree...
... done.

Now access with mpd client:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 686, in run
    for data in results:
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 1060, in cmd_list
    rows = tx.query(statement, subvals)
  File "/usr/lib/python3.7/site-packages/beets/dbcore/db.py", line 709, in query
    cursor = self.db._connection().execute(statement, subvals)
sqlite3.OperationalError: near "ORDER": syntax error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/beet", line 11, in <module>
    load_entry_point('beets==1.4.7', 'console_scripts', 'beet')()
  File "/usr/lib/python3.7/site-packages/beets/ui/__init__.py", line 1256, in main
    _raw_main(args)
  File "/usr/lib/python3.7/site-packages/beets/ui/__init__.py", line 1243, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 1192, in func
    self.start_bpd(lib, host, int(port), password, volume, debug)
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 1168, in start_bpd
    server.run()
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 762, in run
    super(Server, self).run()
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 196, in run
    Connection.handler(self)))
  File "/usr/lib/python3.7/site-packages/beets/util/bluelet.py", line 380, in run
    exit_te.reraise()
  File "/usr/lib/python3.7/site-packages/beets/util/bluelet.py", line 204, in reraise
    six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
  File "/usr/lib/python3.7/site-packages/six.py", line 693, in reraise
    raise value
  File "/usr/lib/python3.7/site-packages/beets/util/bluelet.py", line 266, in advance_thread
    next_event = coro.throw(*value)
  File "/usr/lib/python3.7/site-packages/beets/util/bluelet.py", line 626, in handler
    yield func(conn)
  File "/usr/lib/python3.7/site-packages/beets/util/bluelet.py", line 266, in advance_thread
    next_event = coro.throw(*value)
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 625, in run
    yield bluelet.call(self.do_command(Command(line)))
  File "/usr/lib/python3.7/site-packages/beets/util/bluelet.py", line 266, in advance_thread
    next_event = coro.throw(*value)
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 585, in do_command
    yield bluelet.call(command.run(self))
  File "/usr/lib/python3.7/site-packages/beets/util/bluelet.py", line 268, in advance_thread
    next_event = coro.send(value)
  File "/usr/lib/python3.7/site-packages/beetsplug/bpd/__init__.py", line 702, in run
    log.error('{}', traceback.format_exc(e))
  File "/usr/lib/python3.7/traceback.py", line 163, in format_exc
    return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
  File "/usr/lib/python3.7/traceback.py", line 117, in format_exception
    type(value), value, tb, limit=limit).format(chain=chain))
  File "/usr/lib/python3.7/traceback.py", line 496, in __init__
    capture_locals=capture_locals)
  File "/usr/lib/python3.7/traceback.py", line 331, in extract
    if limit >= 0:
TypeError: '>=' not supported between instances of 'OperationalError' and 'int'

Setup

  • OS: Linux 4.14.62-1-ARCH Finally started to get somewhere :-) #1 SMP Fri Aug 17 05:43:55 UTC 2018 armv7l GNU/Linux
  • Python version: Python 3.7.0
  • beets version: 1.4.7
  • sqlite3 --version: 3.24.0 2018-06-04 19:24:41 c7ee0833225bfd8c5ec2f9bf62b97c4e04d03bd9566366d5221ac8fb199a87ca
  • Turning off plugins made problem go away (yes/no): n/a

My configuration (output of beet config) is:

original_date: yes
directory: /home/hrehfeld/music/2017
library: /home/hrehfeld/.local/beets.blb
ignore: INCOMPLETE~*
ignore_hidden: yes
threaded: yes

plugins: bpd

import:
    log: ~/beets_import.log
    incremental: yes
    move: yes
    languages: [en, de, fr]
    resume: yes
    detail: yes
    searchlimit: 30
    duplicate_action: keep

match:
    strong_rec_thresh: 0.1
    preferred:
        countries: [US, GB|UK, DE]
        media: [CD, Digital Media|File]
        original_year: yes
    max_rec:
        missing_tracks: low
        unmatched_tracks: medium

replace:
    '[\\/]': _
    ^\.: _
    '[\x00-\x1f]': _
    '[<>:"\?\*\|]': _
    \.$: _
    \s+$: ''
    '[,!'']': ''
max_filename_length: 100

paths:
    default: '%bucket{$year}/%bucket{%asciify{$albumartist}}/%asciify{$albumartist} - $year - %asciify{$album}%aunique{}/%asciify{$albumartist} - $track - %asciify{$title}'
lastgenre:
    fallback: unspecified
    canonical: ''
replaygain:
    backend: gstreamer
bucket:
    bucket_alpha: [A-F, G-M, N-Z]
    bucket_year:
    - '1920'
    - '1950'
    - '1960'
    - '1970'
    - '1980'
    - '1990'
    - '2000'
    - '2010'
copyartifacts:
    extensions: .cue .log .jpg .png
    print_ignored: yes
bpd:
    port: 6601
    password: REDACTED
    volume: 100
    host: ''
types:
    rating: int
web:
    host: 127.0.0.1

@sampsyo sampsyo added the needinfo We need more details or follow-up from the filer before this can be tagged "bug" or "feature." label Aug 20, 2018
@sampsyo
Copy link
Member

sampsyo commented Aug 20, 2018

Hmm; that looks pretty bad. Are you able to work out what command the client sent to trigger this crash?

@hrehfeld
Copy link
Author

Hrm, I think it only happens with mpdroid. It seems to spam requests. Will test more sometime soon.

@arcresu
Copy link
Member

arcresu commented Apr 13, 2019

I can reproduce this (with MALP on Android). The problem happens when you're on the list of artists and you select an artist. The client wants to grab a list of albums from that artist. It issues the command:

list album "alt-J"

which is weird because it doesn't seem to match the documentation of the protocol which is list {TYPE} {FILTER} where {FILTER} is a set of key value pairs. That is, I would have expected the command to instead be

list album artist "alt-J"

and indeed our existing implementation is fine with that command.

In any case with the "wrong" command from the client, it causes bpd to construct the query SELECT DISTINCT album FROM items WHERE ORDER BY album with an empty WHERE causing the syntax error noted above. It never made any attempt to check that there was an even number of arguments provided.

I suppose that this means MPD was implementing a behaviour that was a bit different to the documentation of its protocol. Maybe it assumes artist if no tag name is specified for the filter. It's a bit hard to test because the current version of MPD I have supports a newer version of the protocol where the query syntax has changed. I'll have to play around and maybe just guess at what should have happened based on how the client behaves.

@arcresu arcresu added bug bugs that are confirmed and actionable and removed needinfo We need more details or follow-up from the filer before this can be tagged "bug" or "feature." labels Apr 13, 2019
@sampsyo
Copy link
Member

sampsyo commented Apr 13, 2019

Wow; that's quite an undocumented variance! Nice work digging into the root cause. 💯

@arcresu arcresu added this to the Modern MPD support milestone Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs that are confirmed and actionable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants