Bug 8637 - Searching for files with non-ASCII characters on linux works intermittently
: Searching for files with non-ASCII characters on linux works intermittently
Status: CLOSED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Formats
: 7.0.1
: PC Debian Linux
: -- normal (vote)
: 7.x
Assigned To: Andy Grundman
: charset_issues
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-07-02 13:01 UTC by Julius Dauz
Modified: 2009-08-10 02:19 UTC (History)
5 users (show)

See Also:
Category: ---


Attachments
Patch to Slim/Web/Pages/Search.pm (731 bytes, patch)
2008-09-05 13:45 UTC, Markus Schiegl
Details | Diff
Use on_connect_do (858 bytes, patch)
2008-11-18 11:20 UTC, Andy Grundman
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julius Dauz 2008-07-02 13:01:15 UTC
The following is an excerpt from a customer that has reported this issue.

I have installed SqueezeCenter on my Ubuntu/Linux box. I am running Ubuntu 7.04.

SqueezeCenter information:
  SqueezeCenter Version: 7.0.1 - 19705 @ Wed May 14 19:53:57 PDT 2008 - Debian - EN - utf8
  Perl Version: 5.8.8 i486-linux-gnu-thread-multi
  MySQL Version: 5.0.38-Ubuntu_0ubuntu1.4
  Platform Architecture: i686-linux

Everything seems to work fine except when searching from the SqueezeCenter web interface. When searching for something containing non-ASCII chars (e.g. the Danish characters "æøåÆØÅ") like e.g. "røde" I would expect to find 4 songs, but finds nothing. I can browse my way to the songs and all characters are displayed correctly in SqueezeCenter and in my players.

When I restart the SqueezeCenter service like this:
  sudo /etc/init.d/squeezecenter restart
the problem disappears -- searching for "røde" finds the 4 songs I would expect. Then everything works fine for a day or two and then suddenly the problem reappears.
Comment 1 Chris Owens 2008-07-07 10:50:02 UTC
Ross, could you try to reproduce this for a fix in the 7.2 timeframe?
Comment 2 mgd 2008-07-08 07:09:11 UTC
Hello,

I'm the customer that reported the problem.

Currently, my SqueezeCenter is having the problem. If I can in any way be helpful by fetching some logs or maybe enabling some debugging information then please let me know.

Currently searching for "røde" or "Røde" returns nothing whereas searching for "staterne" returns:

 Song titles matching "staterne": 1
 15. Røde i Staterne by Shu-bi-dua from Shu-bi-dua 200 (CD 07)

So as you can see, everything is displayed correctly, but I don't find what I expect when searching for non-ASCII chars.
Comment 3 Ross Levine 2008-07-09 15:59:48 UTC
Very strange; I reproduced this one time but cannot again since. MGD do you ever reboot this system? I ask because I reproduced this and then rebooted, and haven't been able to reproduce since. 

I tagged an artist with røde and searched for that. 
Comment 4 mgd 2008-07-09 16:52:53 UTC
When I first encountered the problem, I rebooted the system after a while (for other reasons) and discovered that the problem disappeared. When I later encountered the problem, I simply restarted the SqueezeCenter service which cured the problem for a while.

Right now, my system is in a state where it does not work and I left it there on purpose if it could in some way help debugging the problem. Please let me know if there is some debug info I can extract from the system which would help you diagnose the problem.
Comment 5 Ross Levine 2008-07-09 17:43:53 UTC
Michael would you mind looking at this? As mentioned I was able to reproduce this first try, maybe you'll be as lucky. 
Comment 6 Michael Herger 2008-07-14 01:55:10 UTC
Hmm... seems to be working fine for me. But then I've already restarted my SC several times since I've rebooted that machine (updates).

Do you see a different locale setting in SC's version string when you run SC right after reboot or after the service's restart?
Comment 7 Ross Levine 2008-07-14 12:49:22 UTC
No it's the same (Debian - EN - iso-8859-1). I'm still able to reproduce this what seems like randomly. I restart my virtual image and search for 'røde' and about 1 in 3 times there are no results. 
Comment 8 Michael Herger 2008-07-14 22:45:36 UTC
> No it's the same (Debian - EN - iso-8859-1). I'm still able to reproduce this

Could you please try with 7.1 and add "--charset=utf8" to your startup parameters?

> what seems like randomly. I restart my virtual image and search for 'røde' and
> about 1 in 3 times there are no results. 

What search field are you using? Always the same?
Comment 9 Ross Levine 2008-07-15 15:38:16 UTC
I'm always clicking search, not using the mouse over search. Thanks for your help (via email) regarding the parameter, I'll try looking at this again after 7.1. 
Comment 10 Ross Levine 2008-07-29 17:05:48 UTC
No longer able to reproduce this with 7.2. I have tried Michael's suggestion and added CHARSET=utf8 to /etc/init.d/squeezecenter. SC7 shows iso-8859-1, so it's possible this isn't the right place still. 

I'll continue to investigate this. MGD, care to try out a nightly?
Comment 11 Ross Levine 2008-07-29 17:53:03 UTC
I know it hasn't been long but, I think I found a way to reproduce this much more easily Michael. I was using a music library of only a few tracks before, now that I'm over 1000 tracks this is reproducible almost every time for me. 
Comment 12 mgd 2008-08-07 16:08:16 UTC
Ross,

(In reply to comment #10)
> I'll continue to investigate this. MGD, care to try out a nightly?

I guess this is no longer necessary since you are able to reproduce yourself. Otherwise, let me know what to do.
Comment 13 Ross Levine 2008-08-07 16:46:55 UTC
(In reply to comment #12)
> I guess this is no longer necessary since you are able to reproduce yourself.
> Otherwise, let me know what to do.

Please hang in there it may take time to better understand this issue and find a solution. Thank you MGD. 
Comment 14 Markus Schiegl 2008-09-02 22:18:35 UTC
recently i ran into the same problem (7.3r23017) on my gentoo linux utf-8 system. I've excluded browser & mySQL from the problem (through various tests) and inserted some debug code into Slim/Web/Pages/Search.pm to better pin-point the problem.

For me the best way to reproduce the problem (so far) seems to be a long running slimserver process. A restart always cured the problem.

I'll report back if/when i find anything...
Comment 15 Markus Schiegl 2008-09-05 13:45:03 UTC
Created attachment 3948 [details]
Patch to Slim/Web/Pages/Search.pm

after applying the patch and if everything is okay (searching for "männer"):

[08-09-04 20:06:14.1986] Slim::Web::Pages::Search::basicSearch (78) type: contributor search: %MÄNNER% q: männer erg: 0
[08-09-04 20:06:14.2037] Slim::Web::Pages::Search::basicSearch (78) type: album search: %MÄNNER% q: männer erg: 0
[08-09-04 20:06:14.2067] Slim::Web::Pages::Search::basicSearch (78) type: genre search: %MÄNNER% q: männer erg: 0
[08-09-04 20:06:14.3501] Slim::Web::Pages::Search::basicSearch (78) type: track search: %MÄNNER% q: männer erg: 3

without any changes (no restart, no configuration changes) a few hours later  (erg is 0 for all queries):

[08-09-05 19:15:41.0735] Slim::Web::Pages::Search::basicSearch (78) type: contributor search: %MÄNNER% q: männer erg: 0
[08-09-05 19:15:41.0782] Slim::Web::Pages::Search::basicSearch (78) type: album search: %MÄNNER% q: männer erg: 0
[08-09-05 19:15:41.0810] Slim::Web::Pages::Search::basicSearch (78) type: genre search: %MÄNNER% q: männer erg: 0
[08-09-05 19:15:41.2398] Slim::Web::Pages::Search::basicSearch (78) type: track search: %MÄNNER% q: männer erg: 0

result:
although nothing obvious has changed Slim::Schema doesn't return any results anymore - with the exactly same input parameters!

any ideas?

next time i'll strace the communication between slimserver.pl and mysql. unfortunately i had to restart SC so the error is gone again.

kind regards,
Markus
Comment 16 Markus Schiegl 2008-09-07 05:51:20 UTC
I've strace'd the communication (SELECT COUNT...) between slimserver.pl and mysqld. This confirmed although in both cases the query is identical ("Ä" is utf8-encoded to "c3 84") i receive different results.
As written above i had previously verified that the mysql-db itself is still working ok - using the external mysql-client - so this lead me to a dead end (sort of).

after some thinking i came up with a new assumption:

mysqld does - as many servers/daemons - some houskeeping with it's worker/child processes. what happens if the tcp-connection (normally to localhost:9092) is closed, e.g. after a long idle time (one night?). could even be the operating system itself...

I've now killed all mysqld processes (NOT slimserver.pl) and restarted the DB with the same parameter, locales, environment and user account. As expected DBI/DBD does the reconnect and SC continues to work without problems, BUT:

Searching with non-ASCII characters fails!

It seems i've found an easy way to reproduce the error...someone else with an external mysqld (not the bundled one) could confirm this behaviour?

I'd suspect something odd within the DBD module concerning reconnects. Maybe it's time to update DBD (from 3.x to 4.x)? I tried, but failed due to various dependencies problems.

Certainly someone else with more perl/dbi/dbd knowledge is needed here...

over and out,
Markus
Comment 17 Michael Herger 2008-09-08 06:12:20 UTC
Andy - did we plan to update DBD::mysql for 7.3? Or any other idea what might be going wrong here? (see comment #15 and comment #16)
Comment 18 Markus Schiegl 2008-09-08 09:35:14 UTC
(In reply to comment #16)
 
> after some thinking i came up with a new assumption:
> 
> mysqld does - as many servers/daemons - some houskeeping with it's worker/child
> processes. what happens if the tcp-connection (normally to localhost:9092) is
> closed, e.g. after a long idle time (one night?). could even be the operating
> system itself...
> 

My long-time test confirms this. I've repeatedly called the following command:

date >> /tmp/mysql-session ; netstat -an | grep 9092 >> /tmp/mysql-session

and without touching SC at all, many hours later the tcp-source port changed indicating the tcp connection to mysql has been reestablished. the result is as expected: searching for files with non-ASCII characters fails.

kind regards,
Markus
Comment 19 Markus Schiegl 2008-10-26 23:23:11 UTC
(In reply to comment #16)

> It seems i've found an easy way to reproduce the error...someone else with an
> external mysqld (not the bundled one) could confirm this behaviour?

Because of other reasons i've switched to an external mysqld (5.0.60) a few weeks ago and can confirm my guess. After restarting mysql searching vor non-ASCII characters fails immediately (it's now a 5 seconds test). Everything else works fine.
Comment 20 Ross Levine 2008-11-11 18:56:39 UTC
Michael, did you need more from me on this bug?
Comment 21 Michael Herger 2008-11-11 23:15:12 UTC
To be honest - I have no idea what exactly is going wrong here. See my comment #17. It's unlikely I'll be able to fix this in 7.3.

Andy - any idea?
Comment 22 James Richardson 2008-11-12 10:29:27 UTC
No target without assignees
Comment 23 James Richardson 2008-11-17 09:17:10 UTC
Andy to make a patch to try setting the ASCII string on reconnect.
Comment 24 Andy Grundman 2008-11-17 09:33:30 UTC
Might be related to SET NAMES UTF8 not being run on reconnect.
Comment 25 Markus Schiegl 2008-11-18 10:50:06 UTC
Hey Andy! you hit the bull's eye :-) I hacked up the following patch to basic search:

Index: Slim/Web/Pages/Search.pm
===================================================================
--- Slim/Web/Pages/Search.pm	(revision 23955)
+++ Slim/Web/Pages/Search.pm	(working copy)
@@ -37,6 +37,9 @@
 	my $player = $params->{'player'};
 	my $query  = $params->{'query'};
 
+        # POC-hack for bug 8637
+	Slim::Schema->storage->dbh->do('SET NAMES UTF8;');
+
 	# set some defaults for the template
 	$params->{'browse_list'}  = " ";
 	$params->{'numresults'}   = -1;

and can confirm that the problem's gone! I can restart mysql many times and after each reconnect the search returns successful.

Leaves the question where to put this command in a no hackish way...

I'll now run a long time test (need to hold off myself doing few svn-updates ;-) to confirm my original findings...
Comment 26 Andy Grundman 2008-11-18 11:20:46 UTC
Created attachment 4292 [details]
Use on_connect_do

Can you try this patch?  It should cause SET NAMES UTF8 to be run on connect and reconnect.
Comment 27 Markus Schiegl 2008-11-18 11:40:43 UTC
This patch works - and is a clean solution! good job...
Comment 28 Andy Grundman 2008-11-18 11:48:13 UTC
Good.  This would mean breaking support for 4.0 MySQL versions.  KDF: There is a comment in here about you running a really old MySQL version, is that still the case?  I don't feel too bad about not supporting it anymore.
Comment 29 KDF 2008-11-18 12:05:52 UTC
mysql 4 is long gone, thanks.
Comment 30 Michael Herger 2008-11-18 22:59:22 UTC
Hold on... MySQL 4.0 or MySQL 4.x would be incompatible? I'm running a 4.1 here...
Comment 31 Andy Grundman 2008-11-19 05:58:25 UTC
4.1 is fine, it's < 4.1 that don't support SET NAMES UTF8.
Comment 32 Chris Owens 2008-11-24 09:15:43 UTC
Andy to commit his patch.
Comment 33 Andy Grundman 2008-11-24 11:14:03 UTC
Fixed in change 24046.
Comment 34 Markus Schiegl 2008-11-24 21:11:21 UTC
long time test confirms this bug is fixed (for me)...thanks!
Comment 35 James Richardson 2008-12-15 12:05:11 UTC
This bug has been fixed in the 7.3.0 release version of SqueezeCenter!

Please download the new version from http://www.slimdevices.com/su_downloads.html if you haven't already.  

If you are still experiencing this problem, feel free to reopen the bug with your new comments and we'll have another look.
Comment 36 Chris Owens 2009-07-31 10:23:34 UTC
Reduce number of active targets for SC