Bug 346148

Summary: Sound notification keeps repeating in infinite loop
Product: [Frameworks and Libraries] frameworks-knotifications Reporter: André M <andre.vmatos>
Component: generalAssignee: Martin Klapetek <mklapetek>
Status: RESOLVED FIXED    
Severity: normal CC: andre.vmatos, aspotashev, kdelibs-bugs, mklapetek
Priority: NOR    
Version: 5.9.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 5.10.0
Sentry Crash Report:

Description André M 2015-04-13 19:26:57 UTC
Some sound notifications (usually for Instant Messaging Error and New Incoming Chat sounds), when triggered, starts playing indefinitely, repeating itself.

Pavucontrol reports kded5 as the origin of the sounds. Killing it makes the sound stops, until new notification.
For Instant Messaging Error sound, sometimes, opening Notification Center and manually closing the connection error notification makes de sound stops after some (some times long) time. Same with New Incoming Chat, when clicking to respond message, but there's no problem with New message, for example.

Looks like at least this two sound notifications executes some kind of loop, enqueuing (a lot of) sound notification in kded5, that aren't cleared/stoped when the notification is handled. This notifications should be a one shot sound only, not semi-infinite loops.

Reproducible: Always

Steps to Reproduce:
1. Get a connection error or new messaging sound in KTP
2. Be driven mad by repeating notification sounds, that doesn't goes away until killing kded5

Actual Results:  
Sounds keeps playing, _seems_ that longer when notification takes longer to be handled (closing or accepting it in notification center).

Expected Results:  
One shot notification sound for each event.

Using complete KF5 git + plasma5 git + KTP 15.03.97 (gits from this week), latest stable pulseaudio.
If matters, tested with Google/GTalk accounts, logged via oauth.
Comment 1 Martin Klapetek 2015-04-13 19:48:40 UTC
Thanks for the report. Does this happen with any other notifications? Like if you try to delete a file in Dolphin? I'm not aware of KDE Telepathy doing anything special with notifications that would cause this...
Comment 2 André M 2015-04-13 22:12:42 UTC
Hi. Thanks for the response. 
Until now, I haven't experienced this kind of issue in any other notification on plasma5. I've sound notifications + huds from a number of other apps, like kdeconnect, and in none of them (besides ktp) I got this issue.
Comment 3 André M 2015-04-14 11:57:07 UTC
Just experienced the same behavior outside KTP. Disconnecting power cord from laptop triggered the known notification sound, but them started repeating like 3x a different sound, that looks like the message notification (but I'm sure its unrelated with KTP), then power disconnect sound, and again (3x s1 + 1x s2), and kept repeating until killed kded5.
I couldn't reproce this bug, though.
I think this bug isn't related to KTP at all, but is commonly triggered by it.
Comment 4 Martin Klapetek 2015-04-14 12:00:29 UTC
Can you check how many kded5 processes you have running? Maybe the process is running multiple times (which it really shouldn't)?
Comment 5 André M 2015-04-14 12:01:38 UTC
Just one proccess for kded5, and one for kded4 (maybe called by some kde4 applications).
Comment 6 Martin Klapetek 2015-04-14 12:04:51 UTC
Ok. Could you try in konsole "killall kded5 && kded5 &" and then when you reproduce it, there should be some KNotification debug output, can you paste that please?
Comment 7 André M 2015-04-14 12:13:37 UTC
(In reply to Martin Klapetek from comment #6)
> Ok. Could you try in konsole "killall kded5 && kded5 &" and then when you
> reproduce it, there should be some KNotification debug output, can you paste
> that please?

Just got this output. After initialization debug messages:

kf5.kded: kded module "ktp_approver" still uses .desktop files ("kded/ktp_approver.desktop"). Please port it to JSON metadata.
kf5.kded: found kded module "ktp_approver" by prepending 'kded_' to the library path, please fix your metadata.
kf5.kded: Successfully loaded module "ktp_approver"
service is "org.kde.StatusNotifierItem-18387-1"
Registering a client interface to the KStatusNotifierWatcher
Registering "org.kde.StatusNotifierItem-18387-1/StatusNotifierItem" to system tray
Calling notify on "Sound"
Changing audio state from  Phonon::LoadingState  to  Phonon::StoppedState 
Calling notify on "Popup"
Changing audio state from  Phonon::StoppedState  to  Phonon::LoadingState 
Changing audio state from  Phonon::LoadingState  to  Phonon::StoppedState 
Changing audio state from  Phonon::StoppedState  to  Phonon::LoadingState 
Changing audio state from  Phonon::LoadingState  to  Phonon::BufferingState 
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
Changing audio state from  Phonon::PlayingState  to  Phonon::BufferingState 
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
Changing audio state from  Phonon::PlayingState  to  Phonon::LoadingState 
Changing audio state from  Phonon::LoadingState  to  Phonon::StoppedState 
Changing audio state from  Phonon::StoppedState  to  Phonon::LoadingState 
Changing audio state from  Phonon::LoadingState  to  Phonon::BufferingState 
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
Changing audio state from  Phonon::PlayingState  to  Phonon::BufferingState 
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
Changing audio state from  Phonon::PlayingState  to  Phonon::LoadingState 
Changing audio state from  Phonon::LoadingState  to  Phonon::StoppedState 
Changing audio state from  Phonon::StoppedState  to  Phonon::LoadingState 
Changing audio state from  Phonon::LoadingState  to  Phonon::BufferingState 
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
Changing audio state from  Phonon::PlayingState  to  Phonon::BufferingState 
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState
...
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState
Failed to find KNotification for dbus_id 13
Changing audio state from  Phonon::PlayingState  to  Phonon::LoadingState
...
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
ktp-approver: Preferred: ()
ktp-approver: Possible: ("org.freedesktop.Telepathy.Client.KTp.TextUi")
ktp-approver: Final: ("org.freedesktop.Telepathy.Client.KTp.TextUi")
Skipped method "moduleDeleted" : Pointers are not supported: KDEDModule*
Changing audio state from  Phonon::PlayingState  to  Phonon::LoadingState
...
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
Changing audio state from  Phonon::PlayingState  to  Phonon::BufferingState 
Changing audio state from  Phonon::BufferingState  to  Phonon::PlayingState 
kcm_keyboard: Fetched layout groups from X server:      layouts: ("br")         variants: ("abnt2")
ktp-approver: Dispatch operation invalidated "org.freedesktop.Telepathy.Qt.Error.ObjectRemoved" "ChannelDispatchOperation finished and was removed"
ktp-approver: 
Closing notification 1
Changing audio state from  Phonon::PlayingState  to  Phonon::StoppedState 
Service  "org.kde.StatusNotifierItem-18387-1" unregistered

End of debug. Note that the blocks "changing audio...", of 7 lines, repeated in each notification sound loop. This sound kept repeating until I clicked in reply in notification popup.
Comment 8 Martin Klapetek 2015-04-14 12:32:15 UTC
Interesting, thanks, that helps.
Comment 9 Martin Klapetek 2015-04-14 14:30:48 UTC
Ah I know what's going on now.

KNotification has code for repeating the notification sound _if_ the notification is marked as persistent. I think I'll add new flag for that.
Comment 10 Martin Klapetek 2015-04-15 11:21:18 UTC
Git commit 5281dbec2188c29f3e236f54cbd24fd26d171365 by Martin Klapetek.
Committed on 15/04/2015 at 11:21.
Pushed by mklapetek into branch 'master'.

Introduce LoopSound flag

Some notifications might want to loop the sound, eg. calling apps
playing the ringing sound which is not wanted to play once. Currently
the sound is looped for all persistent notifications, but that's not
ideal as not all persistent notifications with sound want/need sound
looping. This new LoopSound flag solves that.
REVIEW: 123360
CHANGELOG: Introduce LoopSound flag allowing notifications to play sound
in a loop if they need it

M  +6    -1    src/knotification.h
M  +2    -2    src/notifybyaudio.cpp

http://commits.kde.org/knotifications/5281dbec2188c29f3e236f54cbd24fd26d171365
Comment 11 André M 2015-04-15 17:21:00 UTC
(In reply to Martin Klapetek from comment #10)
> Git commit 5281dbec2188c29f3e236f54cbd24fd26d171365 by Martin Klapetek.
> Committed on 15/04/2015 at 11:21.
> Pushed by mklapetek into branch 'master'.

Awesome work! Thansk for solving it so fast! That was a new record =)
Looking ahead for pulling this solution from git.
Best regards.